Thursday, January 29, 2009

10 implementations for different Transaction Managers in JAVA

A variety of implementations is available that all differs a little bit from one another.

Ad. 1. DataSourceTransactionManager
The simplest implementation available that is capable of managing transaction using a JDBC connection originating from a single DataSource. This transaction manager is capable of managing transactions in any environment as long as the setup uses a DataSource.

Application code that wants to manage transactions using this transaction manager need to obtains JDBC connections either through DataSourceUtils.getConnection() or by using one of Spring's other data-access utility classes, such as the JdbcTemplate. Obtaining a connection directly from the DataSource will prevent the transaction manager from kicking in.

Ad.2. HibernateTransactionManager
PlatformTransactionManager implementation for a single Hibernate SessionFactory. Binds a Hibernate Session from the specified factory to the thread, potentially allowing for one thread-bound Session per factory. SessionFactoryUtils and HibernateTemplate are aware of thread-bound Sessions and participate in such transactions automatically. Using either of those is required for Hibernate access code that needs to support this transaction handling mechanism.

Ad. 3. JdoTransactionManager
PlatformTransactionManager implementation for a single JDO PersistenceManagerFactory. Binds a JDO PersistenceManager from the specified factory to the thread, potentially allowing for one thread-bound PersistenceManager per factory. PersistenceManagerFactoryUtils and JdoTemplate are aware of thread-bound persistence managers and participate in such transactions automatically. Using either of those (or going through a TransactionAwarePersistenceManagerFactoryProxy is required for JDO access code supporting this transaction management mechanism.

Ad. 4. JmsTransactionManager
PlatformTransactionManager implementation for a single JMS ConnectionFactory. Binds a JMS Connection/Session pair from the specified ConnectionFactory to the thread, potentially allowing for one thread-bound Session per ConnectionFactory.

This local strategy is an alternative to executing JMS operations within JTA transactions. Its advantage is that it is able to work in any environment, for example a standalone application or a test suite, with any message broker as target. However, this strategy is not able to provide XA transactions, for example in order to share transactions between messaging and database access. A full JTA/XA setup is required for XA transactions, typically using Spring's JtaTransactionManager as strategy.

Ad. 5. JpaTransactionManager
PlatformTransactionManager implementation for a single JPA EntityManagerFactory. Binds a JPA EntityManager from the specified factory to the thread, potentially allowing for one thread-bound EntityManager per factory. SharedEntityManagerCreator and JpaTemplate are aware of thread-bound entity managers and participate in such transactions automatically. Using either is required for JPA access code supporting this transaction management mechanism.

This transaction manager is appropriate for applications that use a single JPA EntityManagerFactory for transactional data access. JTA (usually through JtaTransactionManager) is necessary for accessing multiple transactional resources within the same transaction. Note that you need to configure your JPA provider accordingly in order to make it participate in JTA transactions.

Ad. 6. JtaTransactionManager
PlatformTransactionManager implementation for JTA, delegating to a backend JTA provider. This is typically used to delegate to a J2EE server's transaction coordinator, but may also be configured with a local JTA provider which is embedded within the application.

This transaction manager is appropriate for handling distributed transactions, i.e. transactions that span multiple resources, and for controlling transactions on application server resources (e.g. JDBC DataSources available in JNDI) in general. For a single JDBC DataSource, DataSourceTransactionManager is perfectly sufficient, and for accessing a single resource with Hibernate (including transactional cache), HibernateTransactionManager is appropriate, for example.

Ad. 7. OC4JJtaTransactionManager
Special JtaTransactionManager variant for Oracle OC4J (10.1.3 and higher). Supports the full power of Spring's transaction definitions on OC4J's transaction coordinator, beyond standard JTA: transaction names and per-transaction isolation levels.

Uses OC4J's special begin(name) method to start a JTA transaction, in orderto make Spring-driven transactions visible in OC4J's transaction monitor. In case of Spring's declarative transactions, the exposed name will (by default) be the fully-qualified class name + "." + method name.

Ad. 8. TopLinkTransactionManager
PlatformTransactionManager implementation for a single TopLink SessionFactory. Binds a TopLink Session from the specified factory to the thread, potentially allowing for one thread-bound Session per factory. SessionFactoryUtils and TopLinkTemplate are aware of thread-bound Sessions and participate in such transactions automatically. Using either of those or going through Session.getActiveUnitOfWork() is required for TopLink access code supporting this transaction handling mechanism.

This transaction manager is appropriate for applications that use a single TopLink SessionFactory for transactional data access. JTA (usually through JtaTransactionManager) is necessary for accessing multiple transactional resources within the same transaction. Note that you need to configure TopLink with an appropriate external transaction controller in order to make it participate in JTA transactions.

Ad. 9. WebLogicJtaTransactionManager
Special JtaTransactionManager variant for BEA WebLogic (7.0, 8.1 and higher). Supports the full power of Spring's transaction definitions on WebLogic's transaction coordinator, beyond standard JTA: transaction names, per-transaction isolation levels, and proper resuming of transactions in all cases.

Uses WebLogic's special begin(name) method to start a JTA transaction, in order to make Spring-driven transactions visible in WebLogic's transaction monitor. In case of Spring's declarative transactions, the exposed name will (by default) be the fully-qualified class name + "." + method name.

Ad. 10. WebSphereTransactionManagerFactoryBean
FactoryBean that retrieves the JTA TransactionManager for IBM's WebSphere application servers (versions 6, 5.1, 5.0 and 4).

Uses WebSphere's static access methods to obtain the JTA TransactionManager, which is different for WebSphere 5.1+, 5.0 and 4.

PL Note ::: This article has been taken from Spring Source (Author Alef Arendsen) http://www.springsource.com

Cheers!!!

Ujjwal B Soni

12 comments:

Ed said...

Great! So how do I configure Spring JtaTransactionManager for use with TopLink Essentials in our test environment (outside of a JEE container)?!

Anonymous said...

Hmm, article text lifted direct from http://forum.springsource.org/showthread.php?t=37929 !

Anonymous said...

spring source people have lifted this text from here......This text is absolutely authentic...

Anonymous said...

It was lifted. Look at the date in Springsource forum. Wonder why Ujjwal did not give credit to the source .....

Unknown said...

Thanks for drawing my attention towards this. I have added a note to my post as well as assigned credits to the Author.

Cheers!!!

Ujjwal B Soni

Anonymous said...

Very good message

Anonymous said...

I inclination not agree on it. I regard as precise post. Specially the title-deed attracted me to study the unscathed story.

Anonymous said...

Amiable post and this enter helped me alot in my college assignement. Gratefulness you on your information.

Unknown said...

Thanks, keep checking my blog...

Unknown said...

Dear Sir, I'm doing my Masters project in Java. T need to implement Local Transaction Manager for the web application. The project title is Scalable transaction Manager for Web application in Cloud. Pls help me to implement LTMs.
dhawasnitin@gmail.com

Unknown said...

Dear Sir, I'm doing my Masters project in Java. T need to implement Local Transaction Manager for the web application. The project title is Scalable transaction Manager for Web application in Cloud. Pls help me to implement LTMs.
dhawasnitin@gmail.com

Unknown said...

Dear Sir, I'm doing my Masters project in Java. T need to implement Local Transaction Manager for the web application. The project title is Scalable transaction Manager for Web application in Cloud. Pls help me to implement LTMs.
dhawasnitin@gmail.com