I was given an "API" in the form of a JAR to do some external accounting operations from my Java-Seam-Hibernate appplication.
Internally, the API is an plain Hibernate application, using two independent data sources besides the one used from Seam itself.
The issue is that one of the "API" operations raises the following Exception when doing an internal .commit():
java.sql.SQLException: You cannot commit during a managed transaction!
at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.jdbcCommit(BaseWrapperManagedConnection.java:543)
at org.jboss.resource.adapter.jdbc.WrappedConnection.commit(WrappedConnection.java:334)
at org.hibernate.transaction.JDBCTransaction.commitAndResetAutoCommit(JDBCTransaction.java:139)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:115)
at com.other.APIAccountingImpl.moneyMovement(APIAccountingImpl.java:261)
at com.myapp.integration.ExternalApiIntegrator.storeAcountingData(ExternalApiIntegrator.java:125)
at com.myapp.session.EmployeeAccounting.persistData(EmployeeAccounting.java:123)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at ...
The source code of the moneyMovement method looks like the standard Hibernate Session transaction idiom:
Session sess = factory.openSession();
Transaction tx;
try {
tx = sess.beginTransaction();
//do some work
...
tx.commit();
}
catch (Exception e) {
if (tx!=null) tx.rollback();
throw e;
}
finally {
sess.close();
}
I'm using Seam managed transactions with JTA. I'm also forced to use the custom API and I'm not allowed to alter the source code.
What are my alternatives? How can I isolate the Seam managed transactions from the "API" Hibernate Session? It is possible to configure a connection from a specific data source to not be a managed trx?