Quote:
Second, is the code you mention executing within/behind an ejb?
Andrew, you havent answered Steves question. But you do mention running inside war. This is not inside EJB, and as such, a UserTransaction is not be managed for you, you must do this yourself using using steves code. Below.
HibernateContext.getSession() expect a JTA transaction to be active, it will fail if one is not present.
Code:
UserTransaction transaction = (UserTransaction) context.lookup("java:/UserTransaction");
transaction.begin();
Session session = HibernateContext.getSession("java:/hibernate/SessionFactory");
// do something
transaction.commit();
IMHO There may be little advantage in converting to the above methodology in your current environment, as you still have to manage the transaction, just in a different way.
The main advantage will be where you have to manage transactions for a secondary resource (not Hibernate), where you would have handle two trasactions in the same code. Using JTA just allows you to see it as one transaction.
The other advantage comes from using EJBs which mange the transactions (JTA) for you. Remember JTA is just a standard way of managing transactions across different components.
Hope this helps.