Search code examples
hibernatejpaglassfishpersistencecontainer-managed

Glassfish/Hibernate save without calling save explicitely


I am using Glassfish 2 and container managed persistence with Hibernate 3.2 as persistence provider. I have some finder method in my business logic, which manipulates some persistent entities, which have been fetched via the EntityManager. The manipulation is just changing a String property (deleting an element from a collection leads to the same effect).
I do not call anything like save or persist on my EntityManager. I just want to return some changed entities to my client.

It seems when the container commits the transaction the changes to my entity are saved automatically. Is there some magic Hibernate or Glassfish behaviour I missed completely so far?


Solution

  • If the entity you've fetched is in Managed state then at the end of transaction, changes made to the entity will be persisted. That's the contract that the JPA provider must obey to.

    This question might be helpful for you: Transactional saves without calling update method