5 Replies Latest reply on Mar 12, 2013 9:14 AM by Anna Manukyan

    Grails 2nd level cache

    Paul Taylor Newbie

      I'm trying to use the grails inifinispan plugin to set up a hibernate 2nd level cache.   I've followed the instructions at http://www.coherentlogic.com/wordpress/?page_id=1452 to enable caching but when I run the application (in both development mode and deployed to Jboss AS 6) I get the following error:

       

       

        Error creating bean with name 'sessionFactory': Invocation of init method failed;

        nested exception is org.hibernate.HibernateException: could not instantiate RegionFactory [org.hibernate.cache.infinispan.InfinispanRegionFactory]

       

      Has any one managed to get this working or is this a problem of incompatable versions?

       

      Environment grails 2.1.0, java 1.6.0_41,  infinispan grails plugin 1.0.3

       

      The hibernate and inifinispan jars bundled with the app are:

       

      WEB-INF/lib/grails-hibernate-2.1.0.jar

      WEB-INF/lib/hibernate-commons-annotations-3.2.0.Final.jar

      WEB-INF/lib/hibernate-commons-annotations-4.0.1.Final.jar

      WEB-INF/lib/hibernate-core-3.6.10.Final.jar

      WEB-INF/lib/hibernate-ehcache-3.6.10.Final.jar

      WEB-INF/lib/hibernate-infinispan-4.0.1.Final.jar

      WEB-INF/lib/hibernate-jpa-2.0-api-1.0.1.Final.jar

      WEB-INF/lib/hibernate-memcached-1.3.jar

      WEB-INF/lib/hibernate-search-engine-4.1.0.Alpha1.jar

      WEB-INF/lib/hibernate-validator-4.1.0.Final.jar

       

      Grails DataSource config:

       

      hibernate {

          cache.use_second_level_cache=true

          cache.use_query_cache=true

          cache.region.factory_class='org.hibernate.cache.infinispan.InfinispanRegionFactory'

      }

       

       

      The org.hibernate.cache.infinispan.InfinispanRegionFactory class is incuded in hibernate-inifispan-4.0.1.Final.jar

       

      Paul

        • 1. Re: Grails 2nd level cache
          Sanne Grinovero Master

          I don't know which versions are suggested by grails, but all the Hibernate libraries you have chosen are not designed to work together: you can't mix random libraries.

           

          For sure you have to remove: hibernate-commons-annotations-3.2.0.Final.jar

           

          For the others it depends on other framework requirements; generally I would advise you to not use JBoss AS6 anymore but take JBoss AS 7.1 or even better to go with JBoss EAP 6.1:

          in these versions all the libraries you need (except hibernate-search) are already aligned, known to be compatible and tested together. If you take that the version of Hibernate Search you need is 4.2.0.Final.

          1 of 1 people found this helpful
          • 2. Re: Grails 2nd level cache
            Anna Manukyan Newbie

            Hi Paul,

             

            a question from my side: in the documentation related to infinispan plugin for grails URLs provided to the created quick starts (demos) - the section Plugin Test / Demo Applications .

             

            Have you tried them? I've tried the one  for Grails 2.0 and it worked properly (although for the application from the scratch I had the same error as you).

            Maybe you can compare the configuration files (BuildConfig.groovy, Config.groovy, Datasource.groovy) to see what's the difference between your implementation and the provided one.

             

            Regards,

            Anna.

            • 3. Re: Grails 2nd level cache
              Paul Taylor Newbie

              I've decided to replace using the grails plugin with a direct dependency so I can have more control over the version of infinispan included and its dependencies.  However even trying different versions I still get the same ClassNotFoundException even though the class is there.

              • 4. Re: Grails 2nd level cache
                Paul Taylor Newbie

                The demo does not have the level 2 caching configuration, but when its changed I still get the same ClassNotFoundException.  Just wondering did you get it working after making the required changed to DataSource.groovy (ie adding cache.region.factory_class='org.hibernate.cache.infinispan.InfinispanRegionFactory').  What version of Grails did you use?

                • 5. Re: Grails 2nd level cache
                  Anna Manukyan Newbie

                  Hi Paul,

                   

                  I've tried the demo for Grails < 2.0.0 (there the Datasource.groovy is changed properly). I've tried the demo with grails 1.3.7 and it worked like a charm. But for another demo, you are right - it still throws ClassNotFoundException, which I can't tell why it happens.

                   

                  Anyway, I liked the idea of including the infinispan dependency directly into application as this way you will not be dependent on the plugin impl (plugin was not developed by us so I can't say why and what is wrong there).

                   

                  Definetly the exception tells that the application doesn't see the hibernate-infinispan library. But should you add it as a dependency in BuildConfig.groovy or something else, I don't know.

                   

                  Regards,

                  Anna.