我正在研究ofbiz。我只是试图从表中删除一条记录,其中有一个字段带有自动生成的序列id。我试图通过简单的方法,使用标签删除记录。但它显示如下错误:
[java] 2014-03-13 11:23:22,584 (http-bio-0.0.0.0-8080-exec-9) [ Log.java:83 :INFO ]
[java] 2014-03-13 11:23:22,599 (http-bio-0.0.0.0-8080-exec-9) [ GenericEntity.java:147:ERROR]
[java] ---- runtime exception report --------------------------------------------------
[java] Exception: java.lang.IllegalStateException
[java] Message: **This object has been flagged as immutable (unchangeable), probably because it came from an Entity Engine cache. Cannot modify an immutable entity object.**
[java] ---- stack trace ---------------------------------------------------------------
[java] java.lang.IllegalStateException: This object has been flagged as immutable (unchangeable), probably because it came from an Entity Engine cache. Cannot modify an immutable entity object.
[java] org.ofbiz.entity.GenericEntity.assertIsMutable(GenericEntity.java:147)
[java] org.ofbiz.entity.GenericEntity.removedFromDatasource(GenericEntity.java:276)
[java] org.ofbiz.entity.GenericDelegator.removeValue(GenericDelegator.java:1081)
[java] org.ofbiz.minilang.method.entityops.RemoveValue.exec(RemoveValue.java:66)
[java] org.ofbiz.minilang.SimpleMethod.runSubOps(SimpleMethod.java:311)
[java] org.ofbiz.minilang.SimpleMethod.exec(SimpleMethod.java:458)
xxxxxxxxx xxxxx .................
我们不能从db表中删除这种类型的记录(那些具有自动生成的序列ID)吗?
答案 0 :(得分:1)
您必须首先从缓存中克隆不可变实例以进行修改。 Here is a thread稍作解释。
答案 1 :(得分:0)
我自己找到了解决方案。实际上,当我检索记录时,我使用了“entity-one”标签,默认情况下,use-cache为“true”。所以我将值use-cache更改为false。所以,我可以删除记录。以下是我在检索记录时使用的片段:
<entity-one value-field="xxx" entity-name="Yyyyy">...</entity-one>
<remove-value value-field="xxx"/>
现在我将use-cache属性指定为false,如下所示:
<entity-one value-field="xxx" entity-name="Yyyyy" **use-cache="false"**>...</entity-one>
<remove-value value-field="xxx"/>
工作正常。 谢谢。