0 Replies Latest reply on Aug 17, 2016 4:48 PM by wdarby

    Wildfly 10 / Spring / Hibernate / Infinispan configuration question

    wdarby

      I am upgrading from JBoss 7.1.1 to Wildfly 10. My application is built on Spring and Hibernate, which I've upgraded to versions 4.3 and 5.2, respectively. Once the initial migration was complete, I decided to enable the Hibernate Second Level Cache using Infinispan. Things appear to be working correctly, but a comment in the Hibernate/Infinispan documentation has made me question if this is configured correctly.

       

      My previous application did not require JTA, using only single database transactions. But, I read that "It is highly recommended that Hibernate is configured with JTA transactions so that both Hibernate and Infinispan cooperate within the same transaction" in the Infinispan user guide. This made me wonder how to correctly configure this with Spring and Hibernate. Below is my adapted configuration based on the Wildfly 10 JPA Reference Guide:

       

      Note:

      1. Using the Spring HibernateTransactionManager rather than a JtaTransactionManager since I do not need a JTA Data Source
      2. Specified hibernate.transaction.manager_lookup_class to use JTA with Hibernate and Infinispan
      3. Did not specify hibernate.transaction.factory_class, relying on manager_lookup_class
      4. Did not set hibernate.current_session_context_class to "jta"

       

      Any comments on the following configuration given the above preconditions would be greatly appreciated.

       

      Spring/Hibernate configuration

      <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
          <property name="dataSource" ref="dataSource"/>
          <property name="mappingResources">
            <list>
              ...
            </list>
          </property>
          <property name="hibernateProperties">
            <props>
              <prop key="hibernate.dialect">org.hibernate.dialect.MySQL57InnoDBDialect</prop>
              <prop key="hibernate.connection.autocommit">false</prop>
              <prop key="hibernate.cache.use_second_level_cache">true</prop>
              <prop key="hibernate.cache.use_query_cache">true</prop>
              <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.infinispan.InfinispanRegionFactory</prop>
              <prop key="hibernate.cache.infinispan.cachemanager">java:jboss/infinispan/container/hibernate</prop>
              <prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</prop>
              ...
            </props>
          </property>
        </bean>
      
      
      <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
          <property name="sessionFactory" ref="sessionFactory"/>
        </bean>
        <tx:annotation-driven transaction-manager="transactionManager" order="10"/>