3 Replies Latest reply on Dec 31, 2013 5:45 PM by Karl von Randow

    Infinispan + Tomcat 7 + JbossTS - 2LC config

    David Faulstich Newbie

      Trying to setup an tomcat 7 using Galder Zamarreño sample but with a few changes.

       

      http://anonsvn.jboss.org/repos/hibernate/core/trunk/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/tm/JBossStandaloneJtaExampleTest.java

       

      Already read following resources:

      https://community.jboss.org/wiki/ImplementingStandaloneJPAJTAHibernateApplicationOutsideJ2EEServerUsingInfinispan2ndLevelCache

      https://docs.jboss.org/author/display/ISPN/Implementing+standalone+JPA+JTA+Hibernate+application+outside+J2EE+server+using+Infinispan+2nd+level+cache

      http://java.dzone.com/articles/how-configure-infinispan

       

      PS: Due to client restrictions I am unable to run infinispan under AS7 or EAP6.

       

       

       

      But, when I try to bind the transaction manager under initial context, getting following error:

       

      java.lang.NullPointerException

                at org.infinispan.transaction.lookup.JBossStandaloneJTAManagerLookup.getTransactionManager(JBossStandaloneJTAManagerLookup.java:61)

                at br.com.infosolo.educa.listener.EMF.contextInitialized(EMF.java:61)

                at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797)

                at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291)

                at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)

                at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)

                at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)

                at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)

                at java.util.concurrent.FutureTask.run(FutureTask.java:138)

                at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

                at java.lang.Thread.run(Thread.java:662)

       

       

       

       

       

      From pom.xml:

       

      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

                <modelVersion>4.0.0</modelVersion>

                <groupId>br.com.infosolo</groupId>

                <artifactId>Empr</artifactId>

                <version>0.0.1-SNAPSHOT</version>

                <packaging>war</packaging>

                <name>Empr</name>

                <description>Cadastro WEB</description>

                <properties>

                          <deltaspike.version>0.4</deltaspike.version>

                          <infinispan.version>5.1.4.FINAL</infinispan.version>

                          <hibernate.version>4.0.1.Final</hibernate.version>

                </properties>

       

       

                <dependencies>

                          <dependency>

                                    <groupId>javax.mail</groupId>

                                    <artifactId>mail</artifactId>

                                    <version>1.4.7</version>

                                    <scope>provided</scope>

                          </dependency>

                          <dependency>

                                    <groupId>com.sun.faces</groupId>

                                    <artifactId>jsf-api</artifactId>

                                    <version>2.1.18</version>

                          </dependency>

                          <dependency>

                                    <groupId>com.sun.faces</groupId>

                                    <artifactId>jsf-impl</artifactId>

                                    <version>2.1.18</version>

                          </dependency>

                          <dependency>

                                    <groupId>javax.servlet</groupId>

                                    <artifactId>jstl</artifactId>

                                    <version>1.2</version>

                          </dependency>

                          <dependency>

                                    <groupId>org.primefaces</groupId>

                                    <artifactId>primefaces</artifactId>

                                    <version>3.5</version>

                          </dependency>

                          <!-- <dependency> <groupId>org.primefaces.extensions</groupId> <artifactId>primefaces-extensions</artifactId>

                                    <version>0.7.0-SNAPSHOT</version> </dependency> -->

                          <dependency>

                                    <groupId>org.primefaces.themes</groupId>

                                    <artifactId>bootstrap</artifactId>

                                    <version>1.0.9</version>

                          </dependency>

       

       

                          <!-- WELD CONFIG CDI -->

                          <dependency>

                                    <groupId>org.jboss.weld.servlet</groupId>

                                    <artifactId>weld-servlet</artifactId>

                                    <version>1.1.12.Final</version>

                          </dependency>

       

       

                          <!-- <dependency> -->

                          <!-- <groupId>javax.enterprise</groupId> -->

                          <!-- <artifactId>cdi-api</artifactId> -->

                          <!-- <scope>provided</scope> -->

                          <!-- <version>1.1</version> -->

                          <!-- </dependency> -->

                          <!-- <dependency> -->

                          <!-- <groupId>org.jboss.weld.servlet</groupId> -->

                          <!-- <artifactId>weld-servlet</artifactId> -->

                          <!-- <version>2.0.1.Final</version> -->

                          <!-- </dependency> -->

       

       

                          <!-- <dependency> -->

                          <!-- <groupId>org.jboss.weld</groupId> -->

                          <!-- <artifactId>weld-core</artifactId> -->

                          <!-- <version>2.0.1.Final</version> -->

                          <!-- <exclusions> -->

                          <!-- <exclusion> -->

                          <!-- <groupId>javax.el</groupId> -->

                          <!-- <artifactId>el-api</artifactId> -->

                          <!-- </exclusion> -->

                          <!-- </exclusions> -->

                          <!-- </dependency> -->

       

       

                          <!-- <dependency> -->

                          <!-- <groupId>org.jboss.weld.servlet</groupId> -->

                          <!-- <artifactId>weld-servlet-core</artifactId> -->

                          <!-- <version>2.0.1.Final</version> -->

                          <!-- <exclusions> -->

                          <!-- <exclusion> -->

                          <!-- <groupId>javax.el</groupId> -->

                          <!-- <artifactId>el-api</artifactId> -->

                          <!-- </exclusion> -->

                          <!-- </exclusions> -->

                          <!-- </dependency> -->

       

       

                          <!-- FIM WELD CONFIG -->

       

       

                          <dependency>

                                    <groupId>joda-time</groupId>

                                    <artifactId>joda-time</artifactId>

                                    <version>2.2</version>

                          </dependency>

                          <dependency>

                                    <groupId>commons-io</groupId>

                                    <artifactId>commons-io</artifactId>

                                    <version>2.4</version>

                          </dependency>

                          <dependency>

                                    <groupId>commons-fileupload</groupId>

                                    <artifactId>commons-fileupload</artifactId>

                                    <version>1.2.2</version>

                          </dependency>

       

       

                          <dependency>

                                    <groupId>org.apache.deltaspike.core</groupId>

                                    <artifactId>deltaspike-core-api</artifactId>

                                    <version>${deltaspike.version}</version>

                                    <scope>compile</scope>

                          </dependency>

       

       

                          <dependency>

                                    <groupId>org.apache.deltaspike.core</groupId>

                                    <artifactId>deltaspike-core-impl</artifactId>

                                    <version>${deltaspike.version}</version>

                                    <scope>runtime</scope>

                          </dependency>

       

       

                          <dependency>

                                    <groupId>org.apache.deltaspike.modules</groupId>

                                    <artifactId>deltaspike-jpa-module-api</artifactId>

                                    <version>${deltaspike.version}</version>

                                    <scope>compile</scope>

                          </dependency>

       

       

                          <dependency>

                                    <groupId>org.apache.deltaspike.modules</groupId>

                                    <artifactId>deltaspike-jpa-module-impl</artifactId>

                                    <version>${deltaspike.version}</version>

                                    <scope>runtime</scope>

                          </dependency>

       

       

                          <dependency>

                                    <groupId>javax.validation</groupId>

                                    <artifactId>validation-api</artifactId>

                                    <version>1.0.0.GA</version>

                          </dependency>

       

       

                          <dependency>

                                    <groupId>org.hibernate</groupId>

                                    <artifactId>hibernate-validator</artifactId>

                                    <version>4.0.0.GA</version>

                          </dependency>

       

       

                          <dependency>

                                    <groupId>org.hibernate</groupId>

                                    <artifactId>hibernate-core</artifactId>

                                    <version>${hibernate.version}</version>

                          </dependency>

       

                          <dependency>

                                    <groupId>org.hibernate</groupId>

                                    <artifactId>hibernate-entitymanager</artifactId>

                                    <version>${hibernate.version}</version>

                          </dependency>

       

       

                          <dependency>

                                    <groupId>org.hibernate.common</groupId>

                                    <artifactId>hibernate-commons-annotations</artifactId>

                                    <version>${hibernate.version}</version>

                          </dependency>

       

       

                          <dependency>

                                    <groupId>com.lowagie</groupId>

                                    <artifactId>itext</artifactId>

                                    <version>2.1.7</version>

                          </dependency>

       

       

                          <dependency>

                                    <groupId>org.apache.poi</groupId>

                                    <artifactId>poi</artifactId>

                                    <version>3.9</version>

                          </dependency>

       

       

                          <dependency>

                                    <groupId>org.apache.poi</groupId>

                                    <artifactId>poi-ooxml</artifactId>

                                    <version>3.9</version>

                          </dependency>

       

       

                          <dependency>

                                    <groupId>org.apache.commons</groupId>

                                    <artifactId>commons-lang3</artifactId>

                                    <version>3.1</version>

                          </dependency>

       

       

                          <dependency>

                                    <groupId>org.slf4j</groupId>

                                    <artifactId>slf4j-api</artifactId>

                                    <version>1.6.4</version>

                                    <scope>compile</scope>

                          </dependency>

       

       

                          <dependency>

                                    <groupId>org.slf4j</groupId>

                                    <artifactId>jcl-over-slf4j</artifactId>

                                    <version>1.6.4</version>

                                    <scope>runtime</scope>

                          </dependency>

       

       

                          <dependency>

                                    <groupId>log4j</groupId>

                                    <artifactId>log4j</artifactId>

                                    <version>1.2.16</version>

                          </dependency>

       

       

                          <dependency>

                                    <groupId>javax.servlet</groupId>

                                    <artifactId>javax.servlet-api</artifactId>

                                    <version>3.0.1</version>

                                    <scope>provided</scope>

                          </dependency>

       

       

                          <dependency>

                                    <groupId>javax.el</groupId>

                                    <artifactId>el-api</artifactId>

                                    <version>2.2</version>

                                    <scope>provided</scope>

                          </dependency>

       

       

       

       

       

       

                          <dependency>

                                    <groupId>org.apache.tomcat.maven</groupId>

                                    <artifactId>tomcat7-maven-plugin</artifactId>

                                    <version>2.0-beta-1</version>

                                    <type>maven-plugin</type>

                                    <scope>provided</scope>

                          </dependency>

       

       

                          <dependency>

                                    <groupId>org.springframework.security</groupId>

                                    <artifactId>spring-security-core</artifactId>

                                    <version>3.1.3.RELEASE</version>

                          </dependency>

       

       

                          <dependency>

                                    <groupId>org.springframework.security</groupId>

                                    <artifactId>spring-security-web</artifactId>

                                    <version>3.1.3.RELEASE</version>

                          </dependency>

       

       

                          <dependency>

                                    <groupId>org.springframework.security</groupId>

                                    <artifactId>spring-security-config</artifactId>

                                    <version>3.1.3.RELEASE</version>

                          </dependency>

       

       

                          <!-- INFINISPAN CONFIGURATION -->

                          <dependency>

                                    <groupId>org.infinispan</groupId>

                                    <artifactId>infinispan-core</artifactId>

                                    <version>${infinispan.version}</version>

                          </dependency>

       

                          <dependency>

                                    <groupId>org.hibernate</groupId>

                                    <artifactId>hibernate-infinispan</artifactId>

                                    <version>${hibernate.version}</version>

                          </dependency>

       

                          <!-- JBOSS TRANSACTIONS -->

                          <dependency>

                                    <groupId>javax.transaction</groupId>

                                    <artifactId>jta</artifactId>

                                    <version>1.1</version>

                          </dependency>

       

                          <dependency>

                                    <groupId>org.jboss.jbossts</groupId>

                                    <artifactId>jbossjta</artifactId>

                                    <version>4.16.4.Final</version>

                          </dependency>

       

                          <dependency>

                                    <groupId>jboss</groupId>

                                    <artifactId>jbossall-client</artifactId>

                                    <version>4.2.2.GA</version>

                          </dependency>

       

                          <dependency>

                                    <groupId>jboss</groupId>

                                    <artifactId>jnpserver</artifactId>

                                    <version>4.2.2.GA</version>

                          </dependency>

       

                </dependencies>

       

       

                <build>

                          <plugins>

                                    <plugin>

                                              <groupId>org.apache.maven.plugins</groupId>

                                              <artifactId>maven-compiler-plugin</artifactId>

                                              <version>2.3.2</version>

                                              <configuration>

                                                        <source>1.6</source>

                                                        <target>1.6</target>

                                              </configuration>

                                    </plugin>

                                    <plugin>

                                              <groupId>org.apache.maven.plugins</groupId>

                                              <artifactId>maven-war-plugin</artifactId>

                                              <version>2.1.1</version>

                                              <configuration>

                                                        <failOnMissingWebXml>false</failOnMissingWebXml>

                                                        <warName>empree</warName>

                                              </configuration>

                                    </plugin>

                                    <plugin>

                                              <groupId>org.apache.tomcat.maven</groupId>

                                              <artifactId>tomcat7-maven-plugin</artifactId>

                                              <version>2.0-beta-1</version>

                                              <configuration>

                                                        <path>/educacaoempreendedora</path>

                                              </configuration>

                                    </plugin>

                          </plugins>

                </build>

       

       

                <repositories>

                          <repository>

                                    <id>central</id>

                                    <name>Maven Central Repository</name>

                                    <url>http://repo1.maven.org/maven2</url>

                          </repository>

       

                          <repository>

                                    <id>jboss-public-repository-group</id>

                                    <name>JBoss Public Maven Repository Group</name>

                                    <url>http://repository.jboss.org/nexus/content/groups/public</url>

                                    <layout>default</layout>

                                    <releases>

                                              <enabled>true</enabled>

                                              <updatePolicy>never</updatePolicy>

                                    </releases>

                                    <snapshots>

                                              <enabled>false</enabled>

                                              <updatePolicy>never</updatePolicy>

                                    </snapshots>

                          </repository>

       

       

                          <repository>

                                    <id>apache</id>

                                    <name>apache</name>

                                    <url>http://repo.maven.apache.org/maven2/</url>

                          </repository>

       

       

                          <repository>

                                    <snapshots>

                                              <enabled>false</enabled>

                                    </snapshots>

                                    <id>prime-repo</id>

                                    <name>PrimeFaces Maven Repository</name>

                                    <url>http://repository.primefaces.org</url>

                                    <layout>default</layout>

                          </repository>

       

       

                          <repository>

                                    <id>sonatype-oss-public</id>

                                    <url>https://oss.sonatype.org/content/groups/public/</url>

                                    <snapshots>

                                              <enabled>true</enabled>

                                    </snapshots>

                          </repository>

                </repositories>

       

       

                <pluginRepositories>

                          <pluginRepository>

                                    <snapshots>

                                              <enabled>false</enabled>

                                    </snapshots>

                                    <id>public</id>

                                    <name>Public Repository Group</name>

                                    <url>https://repository.jboss.org/nexus/content/groups/public/</url>

                          </pluginRepository>

                          <pluginRepository>

                                    <id>apache.snapshots</id>

                                    <name>Apache Snapshots</name>

                                    <url>http://repository.apache.org/content/groups/snapshots-group/</url>

                                    <releases>

                                              <enabled>false</enabled>

                                    </releases>

                                    <snapshots>

                                              <enabled>true</enabled>

                                    </snapshots>

                          </pluginRepository>

                          <pluginRepository>

                                    <id>jboss-public-repository-group</id>

                                    <name>JBoss Public Maven Repository Group</name>

                                    <url>http://repository.jboss.org/nexus/content/groups/public</url>

                                    <layout>default</layout>

                                    <releases>

                                              <enabled>true</enabled>

                                              <updatePolicy>never</updatePolicy>

                                    </releases>

                                    <snapshots>

                                              <enabled>true</enabled>

                                              <updatePolicy>never</updatePolicy>

                                    </snapshots>

                          </pluginRepository>

                </pluginRepositories>

                <organization>

                          <name>Infosolo LTDA</name>

                          <url>www.infosolo.com.br</url>

                </organization>

      </project>

      ----

       

       

      Best regards.

        • 1. Re: Infinispan + Tomcat 7 + JbossTS - 2LC config
          Nibin Jacob Panicker Newbie

          I had a similar requirement to run jpa + l2 cache + infinispan in Tomcat.

           

          The following coniguration worked for me.

           

          hibernate.cache.region.factory_class -> org.hibernate.cache.infinispan.InfinispanRegionFactory

          hibernate.transaction.jta.platform -> org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform

          hibernate.transaction.manager_lookup_class -> org.hibernate.cache.infinispan.tm.HibernateTransactionManagerLookup

           

          I had the following additional dependencies.

           

          <dependency>

            <groupId>org.hibernate</groupId>

            <artifactId>hibernate-infinispan</artifactId>

            <version>4.2.5.Final</version>

            </dependency>

           

          <dependency>

            <groupId>org.jboss.jbossts</groupId>

            <artifactId>jbossjta</artifactId>

            <version>4.16.4.Final</version>

            </dependency>

          • 2. Re: Infinispan + Tomcat 7 + JbossTS - 2LC config
            Karl von Randow Newbie

            Thank you very much for this post, I've tried this solution and it gets me a few more steps ahead. However now when I try to put something into a cache I get an exception:

            java.lang.IllegalArgumentException: Cannot create a transactional context without a valid Transaction instance.

             

            Is this something that you've seen before? In the CacheImpl class the injectDependencies call is made with transactionManager == null so it feels like Infinispan is not aware of the transaction manager somehow.

             

            I'm using Infinispan 6.0. Any hints or suggestions would be most appreciated :-)

            • 3. Re: Infinispan + Tomcat 7 + JbossTS - 2LC config
              Karl von Randow Newbie

              I did get a bit further. If I put these in my Hibernate configuration (note these are for Hibernate 4.3, which has changed some classes around):

              hibernate.transaction.jta.platform=org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform

              hibernate.transaction.factory_class=org.hibernate.engine.transaction.internal.jta.JtaTransactionFactory

               

              Then Hibernate uses JBossTM for the platform, and for its transactions. This means that Hibernate no longer uses JDBCTransacationFactory (WARNING!). If you don't specify a transactionMnaagerLookup for Infinispan (or specify the dummy one) then it will choose org.hibernate.cache.infinispan.tm.HibernateTransactionManagerLookup, which looks to Hibernate and uses whatever its JtaPlatform suggests - which is JBossTM standalone.

               

              So we get Hibernate and Infinispan working nicely together with transactions, and this resolves the IllegalArgumentException I reported above.

               

              HOWEVER. And this is a big however. Hibernate is no longer using JDBC transactions. No one is using JDBC transactions. I believe this is a good blog post to read at this point: http://jbossts.blogspot.com/2012/01/connecting-dots.html The JDBC connection isn't enrolled in the transaction manager. It's quite easy to miss this; I turned on statement logging in PostgreSQL to check for BEGIN and COMMIT. They weren't there.

               

              Solution? I am working on a solution to get Infinispan to hook into Hibernate's Transactions, whatever they are. So Hibernate will continue to use JDBCTransactionFactory, and Infinispan will work with that. If anyone is interested, please get in touch.