4 Replies Latest reply on Nov 5, 2019 8:06 AM by heruan

    Infinispan provider for Hibernate ORM cache in WildFly 18

    heruan

      I'm reading everywhere that to have Infinispan as cache provider for Hibernate ORM it's just a matter of setting "hibernate.cache.use_second_level_cache" to "true" in persistence.xml, but if I do that I get:

       

      Caching was explicitly requested, but no RegionFactory was defined and there is not a single registered RegionFactory

       

      So I try to set also "hibernate.cache.region.factory_class" to "org.infinispan.hibernate.cache.v53.InfinispanRegionFactory" but then I'm getting:

       

      java.lang.ClassNotFoundException: Could not load requested class : org.infinispan.hibernate.cache.v53.InfinispanRegionFactory

       

      Finally, I tried adding this jboss-deployment-structure.xml to my app:

       

      <jboss-deployment-structure>

          <deployment>

              <dependencies>

                  <module name="org.infinispan.hibernate-cache" />

              </dependencies>

          </deployment>

      </jboss-deployment-structure>

       

      and then the exception changed to:

       

       

      java.lang.ClassCastException: class org.infinispan.hibernate.cache.v53.InfinispanRegionFactory cannot be cast to class org.hibernate.cache.spi.RegionFactory (org.infinispan.hibernate.cache.v53.InfinispanRegionFactory is in
      unnamed module of loader 'org.infinispan.hibernate-cache@9.4.16.Final'

       

      I'm out of ideas! What can I try?

        • 1. Re: Infinispan provider for Hibernate ORM cache in WildFly 18
          lafr

          It should not be necessary to set property hibernate.cache.region.factory_class, this is set by the WildFly system as far as I know.

          I'm using second level caching in my application without this property.

           

          Can you show us your complete persistence.xml file?

          Did you use caching with older WildFly versions successfully or just starting to use WildFly now?

          Which configuration you're using? standalone.xml or standalone-full.xml? Any modifications done here?

          • 2. Re: Infinispan provider for Hibernate ORM cache in WildFly 18
            heruan

            Thanks Frank for the interest! I didn't use any caching before. The app is a Spring application, so I define Hibernate properties in application.yml, which is:

             

            spring:

              datasource:

                jndi-name: java:/datasource/service/default

              jpa:

                show-sql: true

                properties:

                  hibernate:

                    cache:

                      use_query_cache: true

                      use_second_level_cache: true

             

            I'm in domain mode with a full-ha profile, the only modification is the datasource:

             

                                <datasource jndi-name="java:/datasource/service/default" pool-name="service_default">

                                    <connection-url>jdbc:postgresql://xx.xx.xx:xx/xx</connection-url>

                                    <driver-class>org.postgresql.Driver</driver-class>

                                    <connection-property name="url">

                                        jdbc:postgresql://xx.xx.xx:xx/xx

                                    </connection-property>

                                    <driver>postgresql</driver>

                                    <security>

                                        <user-name>xxxx</user-name>

                                        <password>xxxx</password>

                                    </security>

                                    <validation>

                                        <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"/>

                                        <background-validation>true</background-validation>

                                        <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"/>

                                    </validation>

                                </datasource>

            • 3. Re: Infinispan provider for Hibernate ORM cache in WildFly 18
              lafr

              Using Spring and not JavaEE is probably the fact which makes the difference.

               

              Searching the forum for "wildfly spring hibernate cache infinispan" I found two similar problems with solution from the past which could help you:

              Hibernate second level cache using Infinispan in cluster defaulting to local cache instead of invalidation

              Wildfly 10 / Spring / Hibernate / Infinispan configuration question

              Especially the first one might be useful.

              • 4. Re: Infinispan provider for Hibernate ORM cache in WildFly 18
                heruan

                Thanks, but I started from that and the effect of setting the region factory class is what I described in my post