Reputation: 387
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)."
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. So it becomes detached. 2) A remove call is made for this detached entity in transaction 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. But according to the spec, an exception should be thrown by remove or transaction commit should fail.
Am I missing something here? what is the reason?
Upvotes: 0
Views: 431
Reputation: 6158
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
.
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.
Upvotes: 4