X
xyzzy12
In Hibernate, we ran into this issue. With nested begin transactions,
the inner rollback or commit affected the outer most transaction
block.
So given:
beginTransaction()
beginTransaction()
insert...
commit() //this commit erroneously committed the outermost
commit block
read() //this read failed since the transaction is closed.
commit()
Our hibernate.current_session_context_class is thread and our
hibernate.transaction.factory_class is
org.hibernate.transaction.JDBCTransactionFactory so we don't have a
proper JTA.
We ended up do a reference counting mutex (is that the correct term?)
in which the inner commit does nothing until the outer commit() is
noticed.
An inner rollback will throw an exception so the outermost rollback
will catch it and roll it back.
The basic pattern we are using is:
XDao dao = XDao.getInstance();
try {
dao.begin();
...operations
dao.commit();
} catch (Exception x) {
dao.rollback(x);
}
This is the particular javadoc that doomed us:
/**
* Begin a unit of work and return the associated <tt>Transaction</tt>
object.
* If a new underlying transaction is required, begin the transaction.
Otherwise
* continue the new work in the context of the existing underlying
transaction.
* The class of the returned <tt>Transaction</tt> object is determined
by the
* property <tt>hibernate.transaction_factory</tt>.
*
*/
public Transaction beginTransaction() throws HibernateException;
thanks for your help.
the inner rollback or commit affected the outer most transaction
block.
So given:
beginTransaction()
beginTransaction()
insert...
commit() //this commit erroneously committed the outermost
commit block
read() //this read failed since the transaction is closed.
commit()
Our hibernate.current_session_context_class is thread and our
hibernate.transaction.factory_class is
org.hibernate.transaction.JDBCTransactionFactory so we don't have a
proper JTA.
We ended up do a reference counting mutex (is that the correct term?)
in which the inner commit does nothing until the outer commit() is
noticed.
An inner rollback will throw an exception so the outermost rollback
will catch it and roll it back.
The basic pattern we are using is:
XDao dao = XDao.getInstance();
try {
dao.begin();
...operations
dao.commit();
} catch (Exception x) {
dao.rollback(x);
}
This is the particular javadoc that doomed us:
/**
* Begin a unit of work and return the associated <tt>Transaction</tt>
object.
* If a new underlying transaction is required, begin the transaction.
Otherwise
* continue the new work in the context of the existing underlying
transaction.
* The class of the returned <tt>Transaction</tt> object is determined
by the
* property <tt>hibernate.transaction_factory</tt>.
*
*/
public Transaction beginTransaction() throws HibernateException;
thanks for your help.