1 2 3 Previous Next 30 Replies Latest reply on Sep 20, 2006 2:32 PM by laszlo.fogas

    Hibernate 2nd lvl Cache for EJB3

    marcreis

      Hi I have a some questions about seting up the hibernate 2nd level Chach. I read some docu on this and mainly followed the http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossCacheHibernate
      I am using 4.0.4.GA all.
      When I use the hibernate-recommended-config.xml from the cache package (renamed to TreeCache-service.xml) I get an exception:

      18:02:41,640 INFO [ServiceConfigurator] Problem configuring service jboss.cache
      :service=MyTreeCache
      org.jboss.deployment.DeploymentException: Exception setting attribute javax.mana
      gement.Attribute@16f8834 on mbean jboss.cache:service=MyTreeCache; - nested thro
      wable: (java.lang.IllegalArgumentException: setCacheMode(): caching mode -1 is i
      nvalid)
       at org.jboss.system.ServiceConfigurator.setAttribute(ServiceConfigurator
      .java:698)
       at org.jboss.system.ServiceConfigurator.configure(ServiceConfigurator.ja
      va:332)
       at org.jboss.system.ServiceConfigurator.internalInstall(ServiceConfigura
      tor.java:460)
       at org.jboss.system.ServiceConfigurator.install(ServiceConfigurator.java
      :171)
       at org.jboss.system.ServiceController.install(ServiceController.java:226
      )
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
      java:39)
      ...
      

      I thought the CacheMode must be wrong and tried around with the other modes, with the REPL_ASYNC I get a step further and get this:
      18:20:56,546 INFO [ServiceConfigurator] Problem configuring service jboss.cache
      :service=MyTreeCache
      org.jboss.deployment.DeploymentException: No Attribute found with name: FetchInM
      emoryState
       at org.jboss.system.ServiceConfigurator.configure(ServiceConfigurator.ja
      va:318)
       at org.jboss.system.ServiceConfigurator.internalInstall(ServiceConfigura
      tor.java:460)
       at org.jboss.system.ServiceConfigurator.install(ServiceConfigurator.java
      :171)
       at org.jboss.system.ServiceController.install(ServiceController.java:226
      )
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
      java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatch)
      ...
      

      So I tryed it with the existing cahes and configured my hibernate.cfg.xml to use :
      <property name="cache.provider_class">org.jboss.ejb3.entity.TreeCacheProviderHook</property>
       <property name="treecache.mbean.object_name">jboss.cache:service=EJB3EntityTreeCache</property>
      

      This works at first, but produces this on the node of the cluster, where my EJB's are "not called".
      17:47:16,078 ERROR [STDERR] java.lang.NullPointerException
      17:47:16,078 ERROR [STDERR] at org.jboss.ejb3.cache.tree.StatefulEvictionPol
      icy.evict(StatefulEvictionPolicy.java:48)
      17:47:16,078 ERROR [STDERR] at org.jboss.cache.eviction.LRUAlgorithm.evictCa
      cheNode(LRUAlgorithm.java:197)
      17:47:16,078 ERROR [STDERR] at org.jboss.cache.eviction.LRUAlgorithm.prune(L
      RUAlgorithm.java:303)
      17:47:16,078 ERROR [STDERR] at org.jboss.cache.eviction.LRUAlgorithm.process
      (LRUAlgorithm.java:55)
      17:47:16,078 ERROR [STDERR] at org.jboss.cache.eviction.EvictionTimerTask.ru
      n(EvictionTimerTask.java:37)
      17:47:16,078 ERROR [STDERR] at java.util.TimerThread.mainLoop(Timer.java:512
      )
      17:47:16,078 ERROR [STDERR] at java.util.TimerThread.run(Timer.java:462)
      


      I also tried it with the "org.jboss.hibernate.cache.DeployedTreeCacheProvider" then it seems that the "EJB3EntityTreeCache" is not looked for but .. (have a look ->)

      18:37:00,312 WARN [DeployedTreeCacheProvider] Unable to locate TreeCache MBean
      under object name [jboss.cache:service=HibernateTreeCache]
      java.lang.RuntimeException: Error creating MBeanProxy: jboss.cache:service=Hiber
      nateTreeCache
       at org.jboss.mx.util.MBeanProxyExt.init(MBeanProxyExt.java:415)
       at org.jboss.mx.util.MBeanProxyExt.<init>(MBeanProxyExt.java:99)
       at org.jboss.mx.util.MBeanProxyExt.create(MBeanProxyExt.java:394)
       at org.jboss.mx.util.MBeanProxyExt.create(MBeanProxyExt.java:349)
       at org.jboss.hibernate.cache.DeployedTreeCacheProvider.start(DeployedTre
      eCacheProvider.java:74)
       at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:
      180)
       at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.jav
      a:1213)
       at de.mediacare.test.util.HibTestUtil.<clinit>(HibTestUtil.java:22)
       at de.mediacare.test.ejbean.NatPersLstSFBean.getNatPersLst(NatPersLstSFB
      ean.java:43)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
      java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.


      So I am kind of confused on what I have to do, too do it right. Most likley I missed some obvious config somewhere...

      Sincerly
      Marc

        • 1. Re: Hibernate 2nd lvl Cache for EJB3
          manik

          Using AS 4.0.4.GA, you're probably using JBoss Cache 1.2.4.SP2. Could you please confirm this with:

          java -jar jboss-cache.jar

          To use the recommendations on the JBossCacheHibernate wiki page you need to upgrade to the latest version of JBoss Cache in the 1.3.x or 1.4.x series: http://labs.jboss.com/portal/jbosscache/download/index.html

          • 2. Re: Hibernate 2nd lvl Cache for EJB3
            marcreis

            Yes, it is the 1.2.4SP2 package (sorry for the late reply).

            I got it to work (more or less) with 1.2.4sp2 with this config:

            <server>
            ...
            <!-- Pesimistic is extremley slow, OPTIMISTIC only > 1.3.0 -->
             <attribute name="NodeLockingScheme">PESSIMISTIC</attribute>
             <attribute name="IsolationLevel">REPEATABLE_READ</attribute>
             <!-- This works for 1.2.4.sp2 -->
             <attribute name="CacheMode">REPL_ASYNC</attribute>
            ...
             <!-- Seems to be unknown in 1.2.4sp2
             <attribute name="FetchInMemoryState">false</attribute>
             -->
            ...
             </mbean>
            </server>
            


            I would like to use a cache >= 1.3.0 though, so
            when I use the 1.3.0sp2 hibernate-recommended-config.xml (only modified the name of the cache) and the 1.3.0.sp2 chache (jboss-cache-jdk50.jar) I get this error:

            16:51:44,625 WARN [ServiceController] Problem starting service jboss.j2ee:ear=t
            estEJB.ear,jar=testEJB.jar,name=NatPersLstSFBean,service=EJB3
            java.lang.RuntimeException: java.lang.NoSuchFieldError: eviction_policy_provider at org.jboss.ejb3.ServiceDelegateWrapper.startService(ServiceDelegateWra
            pper.java:105) at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanS
            upport.java:289) at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMB
            eanSupport.java:245)
             at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
            sorImpl.java:25)
            ...
            org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
             at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
             at $Proxy5.deploy(Unknown Source)
             at org.jboss.system.server.ServerImpl.doStart(ServerImpl.java:482)
             at org.jboss.system.server.ServerImpl.start(ServerImpl.java:362)
             at org.jboss.Main.boot(Main.java:200)
             at org.jboss.Main$1.run(Main.java:464)
             at java.lang.Thread.run(Thread.java:595)
            Caused by: java.lang.NoSuchFieldError: eviction_policy_provider
             at org.jboss.ejb3.cache.tree.PassivationTreeCache.getEvictionPolicy(Pass
            ivationTreeCache.java:42)
             at org.jboss.ejb3.cache.tree.StatefulTreeCache.initialize(StatefulTreeCa
            che.java:164)
             at org.jboss.ejb3.stateful.StatefulContainer.start(StatefulContainer.jav
            a:87)
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
            java:39)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
            sorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:585)
             at org.jboss.ejb3.ServiceDelegateWrapper.startService(ServiceDelegateWra
            pper.java:99)
             ... 138 more
            

            the hibernate.cfg.xml cache part is
            ...
            <property name="cache.provider_class">org.jboss.hibernate.cache.DeployedTreeCacheProvider</property>
             <property name="treecache.mbean.object_name">jboss.cache:service=HibernateTreeCache</property>. ...
            


            Did I again miss something ? It seems like its looking for a "eviction_policy_provider" but I could'nt find anything about this in the wiki, doc or the forum besides the standart config, which I also tried to add to the
            hibernate-recommended-config.xml, since this one doesnt define one in the attributes.
            Sincerly
            marc

            • 3. Re: Hibernate 2nd lvl Cache for EJB3
              marcreis

              I have tryed this with 1.3.0 and 1.4.0.CR1 and I allways get the above error as soon as I deploy the ejb3 application. Just as the error message shows, It doesnt matter If I define a cache service or use a Hibernate 2nd lvl.
              If I dont define one and dont tell Hibernate to use one I still get this error (except with 1.2.4).
              I think it is due to the ejb3 cache part wich looks up an eviciton_policy_provider but seems not to be able to do this anymore when I update the lib/jboss-cache.jar to 1.3.0 or 1.4.0.CR1.
              How do I then update to the new Cache ? I checked the docu and wiki, but they dont tell about anything special to do.
              Sincerly
              Marc

              (I also update various lib/*.jar 's and the ejb3 package to RC8FD, but this did not resolve the issue, I thought this might solve the missmatch. Do I need to flunge the 1.4.0 Sources into the JBoss 4.0.4.GA Sources and do a complete build of all to get the new cache integrated ?)

              • 4. Re: Hibernate 2nd lvl Cache for EJB3

                I just use jboss-cache release 1.4CR2 in 4.0.5 cvs release. I didn't see any problem for both sfsb and entity under all. I must have missed the problem.

                Can you summarize your problem again? I am bit confused since I thought you mentioned that just deploying it will produce the problem.

                • 5. Re: Hibernate 2nd lvl Cache for EJB3
                  marcreis

                  Sure, (sorry for being unclear)

                  The error does not occure when just deploying the 1.3.0 or 1.4.0CR1 jboss-cache.jar into the /lib Folder

                  but as soon as I also deploy my ejb3 application (one SLSB, one SFSB and one POJO used via *.hbm.xml as an entity).
                  It does not matter if I use a hibernate configuration that configures/uses a 2nd lvl Cache or not ("not" meaning the "org.hibernate.cache.NoCacheProvider" defined in the hibernate.cfg.xml), it will always cause the error.
                  With the 1.2.4 cache deployed it never occures.

                  I just tested with a simple SLSB which says "Hello" packed in a jar (with 2 Interfaces), when I change it to an SFSB the error comes up. So it doesent seem to be related to the Hibernate 2nd lvl cache, but rather to the SFSB. I hope this is might give some hints...
                  and thanks for having a look !

                  Sincerly

                  Marc

                  • 6. Re: Hibernate 2nd lvl Cache for EJB3

                    Hmmn... I have just ported some more test cases to 4.0-ejb3 cvs to test out your problems. When use with 1.4CR2, I don't see any problem by just deploying them to deploy dir (both a clustered sfsb and entity). In fact, they passed my unit test as well using 1.4CR2.

                    Have you changed any other config xml?

                    • 7. Re: Hibernate 2nd lvl Cache for EJB3
                      marcreis

                      Yes, I have a modified \deploy\ejb3.deployer\META-INF\jboss-service.xml so that we can use the http-invoker-servlet.
                      This is the changed line:

                      ...
                      <attribute name="InvokerLocator">servlet://mc0430-116:8080/servlet-invoker/ServerInvokerServlet</attribute>
                      ...
                      

                      Also we have modified the

                      "org.jboss.ejb3.stateful.StatefulClusteredProxyFactory" and
                      "StatefulRemoteProxyFactory"
                      "org.jboss.ejb3.stateless.StatelessClusteredProxyFactory" and
                      "StatelessRemoteProxyFactory"

                      so that they allow the usage of the host name rather than the ip address (this is mainly one line seting the String clientBindUrl befor passing it to the InvokerLocator).
                      And some other minor changes that though, are not used in this example or fiddel with ejb3 (InvokerLocator has an extra variable and slight changes and added a new LoadBalancingPolicy).
                      Besides this, the only not "out-of-the-box" files are one "*-ds.xml" for the DB-Source, the "servlet-invoker.war", the tomcat libs copied to the /lib folder for the http invoker to work and the "ojdbc14.jar" for jdbc to the DB. So its actually very minimalistic at the moment. I'll also try 1.4.0.CR2 and see what it says to this.





                      • 8. Re: Hibernate 2nd lvl Cache for EJB3

                        I dont think 1.4CR2 is that different. Can you try it out from AS4.0-ejb3 out of the box though. That should tell you right away.

                        • 9. Re: Hibernate 2nd lvl Cache for EJB3
                          marcreis

                          Strange, I just tried it with an 4.0.4CR2 Out-of-the-Box's "all" and the 1.4.0Cr1 and a "HelloWorld" SFSB and up the error came.
                          I for this I did use a 4.0.4CR2 that has been out for a while, files are dated first of April 06... not that I am missing something here. The sources that I use to compile the modified version of the AS are mainly dated May 22.

                          • 10. Re: Hibernate 2nd lvl Cache for EJB3

                            Please send me your "Hello World" sfsb then. ben dot wang at jboss dot com. I will give it a try to see what is different.

                            • 11. Re: Hibernate 2nd lvl Cache for EJB3
                              marcreis

                              The SFSB should be on its way to you !

                              • 12. Re: Hibernate 2nd lvl Cache for EJB3

                                Marc,

                                I have found out why. Please go to this ejb3 post for details.

                                http://www.jboss.com/index.html?module=bb&op=viewtopic&t=85914

                                Thanks,

                                -Ben

                                • 13. Re: Hibernate 2nd lvl Cache for EJB3
                                  marcreis

                                  Thank you Ben !

                                  Sincerly
                                  Marc

                                  • 14. Re: Hibernate 2nd lvl Cache for EJB3
                                    marcreis

                                    Sorry to bother again, but I do have one more question.
                                    Is there any workaround that I can implement into the 4.0.4.GA source, so that when I build a version it will work with 1.4 ?
                                    I had a look at the JBossCache sources (TreeCache, EvictionPolicy, RegionManager, Region, Eviction,...) and at the hole org.jboss.ejb3.cache.* source, but I dont really see how I could do a work around.
                                    I first thought just using the 1.4 Cache sources in the JBoss sources when building would resolve the issue, but I guess there is more to it ;-). So I tried to see If I could some how get behind what I would need to do at the PassivationTreeCache, but I dont get it yet.

                                    Thanks !

                                    Marc

                                    1 2 3 Previous Next