title: Hibernate / Spring transaction issue with Infinispan L2 cache
body: <p>I am trying to use Infinispan as Hibernate L2 cache for an application which use technologies like Tomcat 6, Hibernate 4 and Spring 3.5. The application running in Tomcat and our current transaction manager is</p>
  
  <pre><code>    org.springframework.orm.hibernate4.HibernateTransactionManager
  </code></pre>
  
  <p>We have introduced following properties to hibernate property file for Infinispan introduction.</p>
  
  <pre><code>hibernate.cache.region.factory_class=org.hibernate.cache.infinispan.InfinispanRegionFactory
  hibernate.transaction.factory_class=org.hibernate.transaction.JTATransactionFactory 
     hibernate.transaction.jta.platform=org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform 
     hibernate.transaction.manager_lookup_class=org.hibernate.cache.infinispan.tm.HibernateTransactionManagerLookup
  </code></pre>
  
  <p>After the introduction of Infinispan we lost the stability of the application and start to get different errors randomly. I assume our Infinispan configurations are not correct (we use a transnational cache). I think our transaction manager and Infinispan transaction settings not match.  Please advice for correct configuration.</p>
  
  <p>Errors we see</p>
  
  <pre><code>    java.lang.IllegalStateException: Transaction TransactionImple &lt; ac, BasicAction: 0:ffff0a1e015a:c2f8:51921dac:3de status: ActionStatus.ABORTED &gt; is not in a valid state to be invoking cache operations on.
  
      org.springframework.transaction.IllegalTransactionStateException: Transaction is already completed - do not call commit or rollback more than once per transaction
  </code></pre>
  
  <p>Infinispan configuration file I use        </p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:infinispan:config:5.1"
                  xsi:schemaLocation="urn:infinispan:config:5.1 http://www.infinispan.org/schemas/infinispan-config-5.1.xsd"&gt;
  
          &lt;global&gt;
              &lt;globalJmxStatistics enabled="true" jmxDomain="org.infinispan" allowDuplicateDomains="true"/&gt;
              &lt;transport
                      transportClass="org.infinispan.remoting.transport.jgroups.JGroupsTransport"
                      clusterName="infinispan-hibernate-cluster"
                      distributedSyncTimeout="50000"
                      strictPeerToPeer="false"&gt;
                  &lt;properties&gt;
                      &lt;property name="configurationFile" value="jgroups.xml"/&gt;
                  &lt;/properties&gt;
              &lt;/transport&gt;
          &lt;/global&gt;
  
          &lt;default&gt;
          &lt;/default&gt;
  
          &lt;namedCache name="aaa-replicated-cache-entity"&gt;
              &lt;clustering mode="replication"&gt;
                  &lt;stateRetrieval fetchInMemoryState="false" timeout="60000"/&gt;
                  &lt;sync replTimeout="20000"/&gt;
              &lt;/clustering&gt;
              &lt;locking isolationLevel="READ_COMMITTED" concurrencyLevel="1000"
                       lockAcquisitionTimeout="15000" useLockStriping="false"/&gt;
              &lt;eviction maxEntries="10000" strategy="LRU"/&gt;
              &lt;expiration maxIdle="100000" wakeUpInterval="5000"/&gt;
              &lt;lazyDeserialization enabled="true"/&gt;
              &lt;transaction useSynchronization="true"                      
                           transactionMode="TRANSACTIONAL" autoCommit="false"
                           lockingMode="OPTIMISTIC"/&gt;
              &lt;loaders passivation="false" shared="false" preload="false"&gt;
                  &lt;loader class="org.infinispan.loaders.cluster.ClusterCacheLoader"
                          fetchPersistentState="false"
                          ignoreModifications="false" purgeOnStartup="false"&gt;
                      &lt;properties&gt;
                          &lt;property name="remoteCallTimeout" value="20000"/&gt;
                      &lt;/properties&gt;
                  &lt;/loader&gt;
              &lt;/loaders&gt;
          &lt;/namedCache&gt;
      &lt;/infinispan&gt;
  
  
      Thanks
  </code></pre>