[英]“Remove” operation on detached entities
I have a question about the remove operation on detached entities. 我对分离实体上的删除操作有疑问。
According to the Spec "If X is a detached entity, an IllegalArgumentException will be thrown by the remove operation (or the transaction commit will fail)." 根据规范“如果X是一个分离的实体,则remove操作将引发IllegalArgumentException(否则事务提交将失败)。”
But the remove operation can be valid for a detached entity. 但是删除操作对于分离的实体可能有效。 Consider the following scenario for a transaction-scoped persistence context: 对于事务范围的持久性上下文,请考虑以下情形:
1) An entity is persisted in the database in transaction T1. 1)实体在事务T1中保留在数据库中。 So it becomes detached. 因此它变得分离。 2) A remove call is made for this detached entity in transaction T2. 2)在事务T2中对此分离实体进行了删除调用。
Because the entity exists in the database, the remove call should be valid and the entity should be removed from the database as a result of transaction T2. 因为实体存在于数据库中,所以删除调用应该是有效的,并且由于事务T2,应该从数据库中删除该实体。 But according to the spec, an exception should be thrown by remove or transaction commit should fail. 但是根据规范,应该由remove引发异常,否则事务提交将失败。
Am I missing something here? 我在这里想念什么吗? what is the reason? 是什么原因?
detached entities
are a non managed entities
, and you are trying to deleting the non managed entity,If you want to remove it, then you have to make it in a managed state
. detached entities
non managed entities
,您要删除该非托管实体。如果要删除它,则必须使其处于managed state
。 or one another way is to find out the references of detached entity and try to remove. 或者另一种方法是找出分离的实体的引用并尝试删除。
getEntityManager().getReference("detached");
remove("reference");
I am not sure about the above line, but you may try it. 我不确定上述内容,但您可以尝试一下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.