I need to use nested transactions. Is that possible? Suppose I have something like this:
Code:
public class User {
public void deductMoney() {
Transaction tx = session.beginTransaction();
setMoney(getMoney() - 10));
tx.commit()
}
public void buyStuff() {
Transaction tx = session.beginTransaction();
stuff = getStuff();
deductMoney();
tx.commit();
}
The call to deductMoney() in buyStuff() should not result i a new transaction, rather it should join the existing transaction that was started in buyStuff().
The API doc for Session.beginTransaction() indicates that it should work this way: "If a new underlying transaction is required, begin the transaction. Otherwise continue the new work in the context of the existing underlying transaction".
Using JDBCTransactionFactory I get "java.sql.SQLException: Can't call commit when autocommit=true".
Using JTATransactionFactory I get "java.lang.IllegalStateException: Can't commit outside of a transaction.
Either the UserTransaction.begin() is missing or the transaction has already been committed or rolled back."
For JTA I've just configured transaction.factory_class in the config file. Maybe there is something else I have to do to get JTA transactions to work? I'm using resin-ee 2.1 as application server.