I'd like to get JTA/EJB-like "join-existing-transaction" semantics in the simple case (sharing a single conn to the same DB, one-phase commit only) in Tomcat without having to dump more JARs in common/lib (e.g., JOTM) or migrate to Spring framework just yet. The default JDBCTransaction does not support this, and I was wondering if there is a solution floating around before reinventing the wheel.
We have code that looks like this:
Code:
A(session) {
tx1 = session.beginTransaction();
... do stuff ...
B(session);
... do more stuff ..
tx1.commit();
}
B(session) {
tx2 = session.beginTransaction();
... do stuff ...
tx2.commit();
}
We want to avoid the default JDBCTransaction behavior, where tx2.commit() in B() will call connection.commit() on the underlying JDBC connection right away, preventing the outer transaction from being able to roll back properly. Has anyone had any luck with a lightweight solution for this, like introducing a ThreadLocal or similar into JDBCTransaction?