Deprecation

This document is DEPRECATED.

Please consider any information here as out of date. DO NOT use this document.

Instead, refer to http://infinispan.org/documentation.

Please update your bookmarks accordingly.

Skip to end of metadata
Go to start of metadata

Introduction

Infinispans predecessor JBossCache requires integration with JTA when used as 2L-cache for a Hibernate application. At the moment of writing this article (Hibernate 3.5.0.Beta3) also Infinspan requires integration with JTA. Hibernate integrated with JTA is already largely used in EJB applications servers, but most users using Hibernate with Java SE outside any EJB container, still use the plain JDBC approach instead to use JTA.

According Hiberante documentation it should also possible to integrate JTA in a standalone application outside any EJB container, but I did hardly find any documentation how to do that in detail. (probably the reason is, that probably 95% of people is using hibernate within a EJB app. server or using SPRING). This article should give you some example how to realize a standalone Hibernate app. outside of a EJB container with JTA integration (and using Infinispan 2nd level cache).

As first thing you have to choose which implementation of TransactionManager to take. This article comes with examples for following OpenSource TransactionManagers:

  1. JBoss
  2. JOTM
  3. Bitronix
  4. Atomikos
Datasource/Transaction interaction
A very important aspect is not forgetting to couple the datasource with your transaction manager. In other words, the corresponding XAResource must be onto the transaction manager, otherwise only DML-statements but no commits/rollbacks are propagated to your database.

JBoss Transactions

The example with JBoss Transactions Transaction Manager was the most complex to implement, as JBoss's TransactionManager and UserTransaction objects are not declared serializable whilst it's JNDI-server isn't able to bind non serializable objects out of the box. Special use of NonSerializableFactory is needed, requiring some additional custom code:

The content of the corresponding complete persistence.xml:

JOTM

The example with JOTM is more simple, but apparently it's JNDI implementation is not useable without wasting any rmi port. So it is not completely 'standalone' as the JNDI service is exposed outside your virtual machine.

Adjust following 2 properties in your persistence.xml:

For using the JTA Hibernate application as servlet in tomcat please read  http://jotm.objectweb.org/current/jotm/doc/howto-tomcat-jotm.html and also https://forum.hibernate.org/viewtopic.php?f=1&t=1003866

Bitronix

The Transaction Manager comes bundled with a fake in memory jndi-implementation which is ideal for standalone purpose. To integrate with Infinispan I did need a ad-hoc pre-alpha improvement (see attached btm-ispn.jar by courtesy of  Mr. Ludivic Orban). BitronixTM offers the so-called Last Resource Commit optimization (aka Last Resource Gambit or Last Agent optimization) and it allows a single non-XA database to participate in a XA transaction by cleverly ordering the resources. "Last Resource Commit" is not part of the XA spec as it doesn't cover the transaction-recovery aspect, so if your database does not support XA (or if you don't wish to have the Xa-driver performance overhead against the plain jdbc) then the "Last Resource Commit" feature should be ideal for the combination 1 single database plus infinispan.

Adjust following 2 properties in your corresponding persistence.xml:

Atominkos

Last but not least, the Atomikos Transaction manager. It is currently the unique Transaction manager I've found with a online-documentation on how to integrate with Hiberantewithout Spring, outside any J2EE container.. It seems to be the unique supporting XaDataSource together with Pooling, so it doesn't matter that It does not come with it's own JNDI implementation (we will use the one of JBoss in following example).

Adjust follwing 2 properties in your corresponding persistence.xml:

And create a file named jta.properties in your classpath with following content:

Labels:
infinispan infinispan Delete
jta jta Delete
hibernate hibernate Delete
2lcache 2lcache Delete
transactionmanager transactionmanager Delete
jpa jpa Delete
standalone standalone Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.