Java-Seam-Hibernateアプリケーションから外部のアカウンティング操作を行うためのJAR形式の「API」が与えられました。管理されたトランザクションを手動でコミットする方法
内部的には、APIは、Seam自身から使用された2つの独立したデータソースを使用するプレーンなHibernateアプリケーションです。
問題は内部.commit()を実行するとき、「API」の操作のいずれかが、次の例外を発生させることである:
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 ...
moneyMovementメソッドのソースコードは標準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();
}
私はJTAとSeam管理トランザクションを使用しています。私もカスタムAPIを使用する必要があり、ソースコードを変更することはできません。
私の選択肢には何がありますか?どのようにしてSeam管理トランザクションを "API" Hibernate Sessionから分離できますか?特定のデータソースから管理されたtrxにならないように接続を設定することは可能ですか?