5 Replies Latest reply on Apr 1, 2008 12:25 AM by Radhika Dawar

    basic question on starting a jboss cache

    Radhika Dawar Newbie

      I have read a lot of documentation on jboss cache and have finally decided to use it for my persistence layer. I am using hibernate and now plan to integrate hibernate with jboss cache for 2nd level caching.
      After reading the documents, I got confused as to how to start jboss cache? Do I have to write my own client code and use its API to start it or is there some run.sh script file which will read my config-cache.xml file for persistence and start the jboss cache thread?
      I would be really thankful if you could provide me this basic information.

        • 1. Re: basic question on starting a jboss cache
          Manik Surtani Master

          Umm, Cache.start() ? :-)

          I take it you have read this chapter in the JBC user guide, and/or the tutorial?

          • 2. Re: basic question on starting a jboss cache
            Brian Stansberry Master

            For the Hibernate 2nd level cache case, how this works depends on what implementation of the org.hibernate.cache.CacheProvider interface you specify when you set the hibernate.cache.provider_class property in you Hibernate config.

            If you use the most common one, org.hibernate.cache.TreeCacheProvider, that class will parse your config file, instantiate your cache and start it for you.

            You tell Hibernate the resource path to your cache config file by setting the hibernate.cache.provider_configuration_file_resource_path property. There's also a deprecated hibernate.cache.tree_cache.config property that does the same thing.

            There's also a org.hibernate.cache.JndiBoundTreeCacheProvider that looks up your cache in JNDI. If you use that, you're responsible for instantiating and starting your cache yourself and getting it bound into JNDI.

            If you are running in JBoss AS with the 'all' config you can also specify org.jboss.ejb3.entity.TreeCacheProviderHook. The package name implies it only works for EJB3 entities, but it should work fine for plain Hibernate usage as well. That one works by finding a running cache in JMX. You get the cache running by naming your "cache-config.xml" file "something-service.xml" and deploying it. You then add the hibernate.treecache.mbean.object_name property to your Hibernate config and use it to specify the ObjectName of your cache.

            • 3. Re: basic question on starting a jboss cache
              Radhika Dawar Newbie

              Thanks a lot bstansberry. Your post was very useful for me.

              According to what u said , I have now configured my hibernate as:


              <!-- JBoss Cache configuration file name -->



              But when I run my application, I get the following error:
              Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss/cache/TransactionManagerLookup
              at java.lang.Class.getDeclaredConstructors0(Native Method)
              at java.lang.Class.privateGetDeclaredConstructors(Class.java:2357)
              at java.lang.Class.getConstructor0(Class.java:2671)
              at java.lang.Class.newInstance0(Class.java:321)
              at java.lang.Class.newInstance(Class.java:303)
              at org.hibernate.cfg.SettingsFactory.createCacheProvider(SettingsFactory.java:375)
              .....................

              So in my configuration file I added another configuration:


              Now I get the error:
              Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.HibernateException: Could not instantiate TransactionManagerLookup 'org.jboss.cache.transaction.GenericTransactionManagerLookup'
              at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:720)
              at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
              at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
              at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
              at TestPersistence.main(TestPersistence.java:18)
              Caused by: org.hibernate.HibernateException: Could not instantiate TransactionManagerLookup 'org.jboss.cache.transaction.GenericTransactionManagerLookup'
              at org.hibernate.transaction.TransactionManagerLookupFactory.getTransactionManagerLookup(TransactionManagerLookupFactory.java:47)
              at org.hibernate.cfg.SettingsFactory.createTransactionManagerLookup(SettingsFactory.java:422)
              at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:140)
              at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2073)
              at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1298)
              at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:713)
              ... 4 more


              What could be the problem?

              • 4. Re: basic question on starting a jboss cache
                Brian Stansberry Master

                Please use the "code" button when pasting XML and such. You can click the "Preview" button before posting to see if your post will display correctly.

                Now guessing what your post was...

                Are you specifying:

                hibernate.transaction.manager_lookup_class=org.jboss.cache.transaction.GenericTransactionManagerLookup


                If so, that's not valid; Hibernate expects hibernate.transaction.manager_lookup_class to specify of Hibernate's TransactionManagerLookup interface, which is a different thing from the JBC one -- different package.

                I think there's something else going on as well, since you shouldn't get a CNFE. Make sure the JBC jars are on your classpath.

                • 5. Re: basic question on starting a jboss cache
                  Radhika Dawar Newbie

                  thanks bstansberry for the information.
                  I have been able to solve my problem. My persistence.xml has the following configuration:

                  <property name="hibernate.cache.use_second_level_cache" value="true" />
                   <property name="hibernate.cache.provider_class" value = "org.hibernate.cache.TreeCacheProvider"/>
                  


                  It does not include

                  <property name="hibernate.transaction.manager_lookup_class" value="org.jboss.cache.TransactionManagerLookup" />
                  
                  

                  My treecache.xml mentions about the transaction manager lookup class as:
                  org.jboss.cache.GenericTransactionManagerLookup

                  This is now working correctly.
                  Thanks.