Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

when an entity stops to be managed in JPA

Tags:

jpa

entity

I'm talking about JPA in JavaEE. In a book that i read talk about:

EntityManager em;
em.find(Employee.class, id);

"This is all the information needed by the entity manager to find the instance in the database, and when the call completes, the employee that gets returned will be a managed entity, meaning that it will exist in the current persistence context associated with the entity manager - pro-ejb3-jpa". But i don't know when an entity stop to be managed and i have to merge() to be managed again if i want to update, delete...

like image 231
Lost Heaven 0809 Avatar asked Feb 13 '23 12:02

Lost Heaven 0809


1 Answers

By default, the persistence context is bound to the transaction. So the context is closed when the transaction is committed or rolled back. And once its closed, your entity, which was managed by the persistence context, becomes unmanaged.

like image 62
JB Nizet Avatar answered Feb 16 '23 02:02

JB Nizet