Hello people
I have a problem with the nested trnasactions with the 3.0.2.cr5:
Code:
Session session = factory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
// Do some work
session.load(...);
session.persist(...);
Transaction nested = null;
try {
nested = session.beginTransaction();
// Do some work
session.load(...);
session.persist(...);
nested.commit();
}catch(RuntimeException e){
nested.rollback();
}
if (nested.wasCommited()){
// Do some work
session.load(...);
session.persist(...);
}else{
// Do some other work
session.load(...);
session.persist(...);
}
tx.commit(); // place which causes an exception now
}
catch (RuntimeException e) {
tx.rollback();
throw e;
}
finally {
session.close();
}
in result I found and exception:
Code:
Exception in thread "main" org.hibernate.TransactionException: Transaction not successfully started
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:100)
....
It was working in the 3.0.5 but now it's broken see code of hibernate code
Code:
SessionImpl.java frgment :
public Transaction beginTransaction() throws HibernateException {
errorIfClosed();
if ( rootSession != null ) {
// todo : should seriously consider not allowing a txn to begin from a child session
// can always route the request to the root session...
log.warn( "Transaction started on non-root session" );
}
Transaction result = getTransaction();
result.begin();
return result;
}
public Transaction getTransaction() throws HibernateException {
errorIfClosed();
return jdbcContext.getTransaction();
}
JDBCContext.java frgment :
public Transaction getTransaction() throws HibernateException {
if (hibernateTransaction==null) {
hibernateTransaction = owner.getFactory().getSettings()
.getTransactionFactory()
.createTransaction( this, owner );
}
return hibernateTransaction;
}