java - How to manually commit a managed transaction -


i given "api" in form of jar external accounting operations java-seam-hibernate appplication.

internally, api plain hibernate application, using 2 independent data sources besides 1 used seam itself.

the issue 1 of "api" operations raises following exception when doing internal .commit():

java.sql.sqlexception: cannot commit during managed transaction!     @ org.jboss.resource.adapter.jdbc.basewrappermanagedconnection.jdbccommit(basewrappermanagedconnection.java:543)     @ org.jboss.resource.adapter.jdbc.wrappedconnection.commit(wrappedconnection.java:334)     @ org.hibernate.transaction.jdbctransaction.commitandresetautocommit(jdbctransaction.java:139)     @ org.hibernate.transaction.jdbctransaction.commit(jdbctransaction.java:115)     @ com.other.apiaccountingimpl.moneymovement(apiaccountingimpl.java:261)     @ com.myapp.integration.externalapiintegrator.storeacountingdata(externalapiintegrator.java:125)     @ com.myapp.session.employeeaccounting.persistdata(employeeaccounting.java:123)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source)     @ ... 

the source code of moneymovement method looks standard hibernate session transaction idiom:

session sess = factory.opensession(); transaction tx; try {     tx = sess.begintransaction();     //do work     ...     tx.commit(); } catch (exception e) {     if (tx!=null) tx.rollback();     throw e; } {     sess.close(); } 

i'm using seam managed transactions jta. i'm forced use custom api , i'm not allowed alter source code.

what alternatives? how can isolate seam managed transactions "api" hibernate session? possible configure connection specific data source not managed trx?

you using jta, java ee standard transaction management. in case, using managed transaction. means container (jboss, seems) handling transaction boundaries, , use jta semantics rollback transaction in case throw exception. in scenario, don't deal transaction api directly. throw exception in case wrong happens, , it'll take care of rolling other parts of transaction.

that said, i'd recommend confirm jar received jta api. if it's not, you'll need documentation it. if is, can use transaction api (and annotations) use explicit demarcation of transactions. (some documentation available here: http://download.oracle.com/javaee/5/tutorial/doc/bnciy.html#bnciz)

overall, it's idea let container manage transactions, transaction in context of business method, may involve 2 or more dao calls, thus, existing beyond transactions you'd have inside each dao method.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -