Explicit commit during a long-running transaction in EclipseLink
393585Oct 26 2010 — edited Nov 2 2010Hi,
I am currently upgrading a J2EE application from OAS with Toplink Essentials to WL 10.3.3 with Eclipselink and have the following issue with transactions.
The application was developed to have long-running transactions for business reasons in specific scenarios. However, some other queries must be created and committed along the way to make sure that we have this specific data in the database before the final commit. This call (and subsequent code) is in an EJB method that has the "@TransactionAttribute(TransactionAttributeType.REQUIRED)" defined on it. Taking this out gives me the same behaviour.
The application has the following implementation of the process, which fails:
Code
EntityManager em = PersistenceUtil.createEntityManager();
em.getTransaction().begin();
PersistenceUtil.saveOrUpdate(em,folder);
em.getTransaction().commit(); --->>>>FAILS HERE
Error
javax.ejb.EJBTransactionRolledbackException: EJB Exception: : javax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLException: Cannot call Connection.rollback in distributed transaction. Transaction Manager will commit the resource manager when the distributed transaction is committed.
So I tried the following to see if it would work, but I believe that the transaction end and anything after that will fail since it requires a transaction to continue
PersistenceUtil.getUnitOfWork().writeChanges();
PersistenceUtil.getUnitOfWork().commit();
Error
javax.persistence.TransactionRequiredException: joinTransaction has been called on a resource-local EntityManager which is unable to register for a JTA transaction.
Can anyone help me as to how to commit a transaction within the long running transaction in this environment? I also want to be sure that the long-running transaction does not fail or is not stopped along the way.
Thanking you in advance