0

I have an EJB, whose method (among other things) load an entity and modify it. If the method completes then modifications of that entity automatically committed to database without calling EntityManager.saveOrUpdate() method? And when the method fails then the transaction of that EJB method will be rolledback along with the modifications of that entity?

1 Answer 1

1

With EJB implicitly your method is bound with a transaction. If you load the entity with the entity manager, the entity is attached with the persistent context, so if you do modifications on the object, upon transaction end, if all goes right the transaction commits and the modifications are flushed to the database, otherwise if some error happens the transaction rolls back, and the modifications are discarded.

1
  • If something goes wrong and an exception is thrown, rolling back depends on whether its a runtime exception or not, or whether its been declared with the @ApplicationException annotation. See blog.dblevins.com/2010/07/… Feb 9, 2012 at 19:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.