entities of type `XXX` can not be updated since they are immutable. Entity ids are [1] 问题排查

在图数据库中,默认实体是可变的,允许修改和存储新版本。然而,对于不会改变的实体,推荐标记为不可变以提高性能。当尝试更新不可变实体时,系统会报错。业务逻辑需考虑实体的immutable属性,必要时设为false。
摘要由CSDN通过智能技术生成

今天发布完subgraph的时候控制台报了这样的错误

Error: Failed to transact block operations: internal constraint violated: entities of type `Gravatar` can not be updated since they are immutable. Entity ids are [1]

意思是当前的实体不能更新,因为它们是不可变的!

引用官方文档的一段话:

By default, entities are mutable, meaning that mappings can load existing entities, modify them and store a new version of that entity. Mutability comes at a price, and for entity types for which it is known that they will never be modified, for example, because they simply contain data extracted verbatim from the chain, it is recommended to mark them as immutable with @entity(immutable: true) . Mappings can make changes to immutable entities as long as those changes happen in the same block in which the entity was created. Immutable entities are much faster to write and to query, and should therefore be used whenever possible.

默认情况下,实体是可变的,这意味着映射可以加载现有实体,修改它们并存储该实体的新版本。可变性是有代价的,对于已知永远不会被修改的实体类型,例如,因为它们只是包含从链中逐字提取的数据,建议使用@entity(immutable: true)将它们标记为不可变。映射可以对不可变实体进行更改,只要这些更改发生在创建实体的同一块中。不可变实体的读写速度要快得多,因此应该尽可能使用不可变实体。

也就是说当我们的业务逻辑需要更新存储在graph节点里面的实体时,需要把实体的immutable属性设置为false。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值