8 Replies Latest reply on Sep 23, 2014 12:34 PM by Hamza ben

    JPA cache store - JBoss AS 7 JTA configuration

    Palo Vanek Newbie

      What is the correct configuration of the Infinispan cache with JPA store on JBoss AS 7?

       

      If I don't configure the hibernate.transaction.manager_lookup_class explicitly in persistence.xml, Infinispan doesn't find the transaction manager.

      When I do I get an *java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction()*, when I try to put an Entity into the cache.

       

      Am I missing something? I would appreciate any working example.

       

       

      h5. My configuration:

       

      *- JBoss AS 7.1.1.Final*

      *- Infinispan 5.3.0.CR1 - installed as a JBoss module*

       

      h6. persistence.xml :

      {code}

      <persistence-unit name="myPU" transaction-type="JTA">

           <description>myPU Persistence Unit</description>

           <provider>org.hibernate.ejb.HibernatePersistence</provider>

           <jta-data-source>java:/datasources/myPU</jta-data-source>

           <class>com.model.Test</class>

           <exclude-unlisted-classes>false</exclude-unlisted-classes>

           <properties>

                <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>

                <property name="hibernate.hbm2ddl.auto" value="validate"/>

                <property name="hibernate.show_sql" value="${showSql}"/>

                <property name="hibernate.format_sql" value="true"/>

                <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>

                <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>

           </properties>

      </persistence-unit>

      {code}

       

      h6. Cache configuration:

      {code}

      public void init() {

           Configuration configuration = new ConfigurationBuilder()

                          .loaders().addLoader(JpaCacheStoreConfigurationBuilder.class)

                          .persistenceUnitName("myPU")

                          .entityClass(Test.class)

           .transaction().transactionManagerLookup(new GenericTransactionManagerLookup())

           .build();

       

           DefaultCacheManager cacheManager = new DefaultCacheManager();

           cacheManager.defineConfiguration("jpaCache", configuration);

           jpaCache = cacheManager.getCache("jpaCache");

      }

      {code}

       

      h6. Usage:

      {code}

           public void putIntoCache(byte[] payload) {

                jpaCache.put("name", new Test());

           }

      {code}

       

      h5. Stacktrace:

      {code}

      ...

      Caused by: java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction()

           at org.hibernate.ejb.AbstractEntityManagerImpl.getTransaction(AbstractEntityManagerImpl.java:996) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]

           at org.infinispan.loaders.jpa.JpaCacheStore.storeLockSafe(JpaCacheStore.java:370) [infinispan-cachestore-jpa-5.3.0.CR1.jar:5.3.0.CR1]

           at org.infinispan.loaders.jpa.JpaCacheStore.storeLockSafe(JpaCacheStore.java:69) [infinispan-cachestore-jpa-5.3.0.CR1.jar:5.3.0.CR1]

           at org.infinispan.loaders.LockSupportCacheStore.store(LockSupportCacheStore.java:213) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.interceptors.CacheStoreInterceptor.visitPutKeyValueCommand(CacheStoreInterceptor.java:242) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:83) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:120) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.interceptors.CacheLoaderInterceptor.visitPutKeyValueCommand(CacheLoaderInterceptor.java:113) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:83) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:120) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.interceptors.EntryWrappingInterceptor.invokeNextAndApplyChanges(EntryWrappingInterceptor.java:290) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.interceptors.EntryWrappingInterceptor.visitPutKeyValueCommand(EntryWrappingInterceptor.java:157) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:83) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:120) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.interceptors.locking.AbstractLockingInterceptor.visitPutKeyValueCommand(AbstractLockingInterceptor.java:70) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:83) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:120) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.interceptors.base.CommandInterceptor.handleDefault(CommandInterceptor.java:134) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.commands.AbstractVisitor.visitPutKeyValueCommand(AbstractVisitor.java:54) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:83) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:120) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.interceptors.InvocationContextInterceptor.handleAll(InvocationContextInterceptor.java:128) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.interceptors.InvocationContextInterceptor.handleDefault(InvocationContextInterceptor.java:92) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.commands.AbstractVisitor.visitPutKeyValueCommand(AbstractVisitor.java:54) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:83) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.interceptors.InterceptorChain.invoke(InterceptorChain.java:343) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.CacheImpl.executeCommandAndCommitIfNeeded(CacheImpl.java:1337) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.CacheImpl.putInternal(CacheImpl.java:898) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.CacheImpl.put(CacheImpl.java:890) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.CacheImpl.put(CacheImpl.java:1390) [infinispan-core.jar:5.3.0.CR1]

           at org.infinispan.CacheImpl.put(CacheImpl.java:229) [infinispan-core.jar:5.3.0.CR1]

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_17]

           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_17]

           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_17]

           at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_17]

           at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

           at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:374) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

           at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:127) [jboss-as-weld-7.1.1.Final.jar:7.1.1.Final]

           at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:135) [jboss-as-weld-7.1.1.Final.jar:7.1.1.Final]

           at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:36) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

           at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

           at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:36) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

           at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]

           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

           at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:82) [jboss-as-weld-7.1.1.Final.jar:7.1.1.Final]

           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

           at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

           at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

           at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

           at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

           at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInCallerTx(CMTTxInterceptor.java:202) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

           ... 124 more

       

      {code}