The Hibernate Session API is independent of any transaction demarcation system in your architecture. We can use the Hibernate uses with JDBC directly through a connection pool, then we can begin and end the transactions by calling the JDBC API. If we run in a J2EE application server, then we might want to use bean-managed transactions and call the JTA API and UserTransaction when needed.
To keep code portable between these two (and other) environments we recommend the optional Hibernate Transaction API, which wraps and hides the underlying system. Here we need to specify a factory class for Transaction instances by setting the Hibernate configuration property hibernate.transaction.factory_class.
There are three standard:
1. org.hibernate.transaction.JDBCTransactionFactory
2. delegates to database (JDBC) transactions (default)
3. org.hibernate.transaction.JTATransactionFactory
We need to delegates to container-managed transactions if an existing transaction is underway in this context (for example, EJB session bean method). Otherwise, a new transaction is started and bean-managed transactions are used.
1. org.hibernate.transaction.CMTTransactionFactory
2. delegates to container-managed JTA transactions
Now we need to define the own transaction strategies (for a CORBA transaction service, for example).
Some features in Hibernate (the second level cache, Contextual Sessions with JTA, etc.) require access to the JTA TransactionManager in a managed environment. In an application server, since J2EE does not standardize a single mechanism, you have to specify how Hibernate should obtain a reference to the TransactionManager:
JTA TransactionManagers is as given below in the table:
Transaction Factory
|
Application Server
|
org.hibernate.transaction.JbossTransactionManagerLookup
|
Jboss
|
org.hibernate.transaction.WeblogicTransactionManagerLookup
|
Weblogic
|
org.hibernate.transaction.WebSphereTransactionManagerLookup
|
WebSphere
|
org.hibernate.transaction.WebSphereExtendedJTATransactionLookup
|
WebSphere 6
|
org.hibernate.transaction.OrionTransactionManagerLookup
|
Orion
|
org.hibernate.transaction.ResinTransactionManagerLookup
|
Resin
|
org.hibernate.transaction.JOTMTransactionManagerLookup
|
JOTM
|
org.hibernate.transaction.JonASTransactionManagerLookup
|
JonAS
|
org.hibernate.transaction.Jrun4TransactionManagerLookup
|
Jrun4
|
org.hibernate.transaction.BESTransactionManagerLookup
|
Borland ES
|