I used EJB3.0 to manage transaction over hibernate, I config the following ptoperties in config file,
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.SunONETransactionManagerLookup</property>
1) I know hibernate uses hibernate.transaction.manager_lookup_class to locate transaction manager in application server, my explanation of what hibernate does is hibernate uses transaction manager to locate a stated transaction in the context(maybe in the local thread) and synchronize hibernate transaction operation to that transaction, is it right?
2) If I use jta to manage transaction, code may look like this:
UserTransaction tx = (UserTransaction) (new InitialContext()).lookup("java:comp/UserTransaction");
tx.begin();
Session session = HibernateUtil.openSession();
....
session.flush();
session.close();
tx.commit();
The code runs fine, but how can a transaction rollback after connection has been closed( session.close(); )?
|