Tuesday, March 15, 2011

em.getTransaction().commit();

if you "manually" commit a transaction, you might get:

javax.ejb.EJBTransactionRolledbackException: Illegal to call this method from injected, managed EntityManager

in this case you should annotate the method:
@TransactionManagement(TransactionManagementType.BEAN)

to make the transaction management "manual".

You can't have both worlds: either you let the container manage the "begin/end/rollback" lifecycle, or you manage it in its entirety.

No comments: