Hibernate version: 2.1.6
Name and version of the database you are using: Oracle 8i
Hi all,
I am doing just a simulation operation in my db, and after the process i need to rollback all that was generated:
Code:
public Object simulate(...) {
Object ret = null;
Connection con = null;
Transaction trans = null;
Session session = null;
beginSession();
try {
trans = session.beginTransaction();
con = session.connection();
ret = calculate(con); // <<<<< legacy method that uses a Connection object
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
trans.rollback(); // <<<<< the exception occurs here
} catch (Exception e) {
e.printStackTrace();
} finally {
endSession();
}
}
return ret;
}
public Object calculate(Connection con) {
// performs all the processing over db
}
But I am getting this exception:
java.sql.SQLException: You cannot rollback during a managed transaction!
at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.jdbcRollback(BaseWrapperManagedConnection.java:537)
at org.jboss.resource.adapter.jdbc.WrappedConnection.rollback(WrappedConnection.java:483)
at net.sf.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:86)
at br.com.softplan.saj.sgmp.dao.hbn.HbnCalculocustaDAO.simuleCustas(HbnCalculocustaDAO.java:411)
at br.com.softplan.saj.sgmp.ejb.impl.CalculocustaBean.simuleCustas(CalculocustaBean.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:683)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)
at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:72)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:315)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:148)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:111)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
at org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessionContainer.java:331)
at org.jboss.ejb.Container.invoke(Container.java:709)
...
How can I rollback the transaction??