9.4.7 managed entity
You can use the contains() method of EntityManager to obtain information about whether the entity instance is being managed with the current persistence context.
This section describes the conditions for the return value of the contains() method.
-
Conditions when the contains() method returns true
-
When the entity is acquired from the database and is not deleted from EntityManager, or is not separated
-
When the entity instance is generated and the persist method is executed for that entity or the persist operation is propagated to that entity
-
-
Conditions when the contains() method returns false
-
When the entity instance is separated
-
When the remove method is executed for the entity or the remove operation is propagated to the entity
-
When the entity instance is generated and the persist method is not executed for that entity or the persist operation is not propagated to that entity
-
The actual insert and delete processing in the database is delayed until the conclusion of the transaction. At the same time, note that the propagation of persist and remove is applied immediately with the contains method.
Make sure that the entity instance is only managed using a single persistence context in the application. With Cosminexus JPA Provider, the operations do not function properly when the same Java instance is managed with multiple persistence contexts.