5 Replies Latest reply on Sep 10, 2009 9:48 AM by Galder Zamarreño

    JBoss Cache (PojoCache) with Hibernate Collections (Persiste

    Maxime Leur Newbie


      I am using PojoCache to store Pojo Objects created by Hibernate.
      I want to use the replication mode with this cache, so I pre-compile with aopc (ant task) my classes.

      But when I call PojoCache.putObject with an Object (which contains collections) loaded by Hibernate, I have an exception :

      Caused by: org.jboss.cache.CacheException: failure creating proxy
      at org.jboss.cache.aop.CollectionClassHandler.collectionObjectPut(CollectionClassHandler.java:124)
      at org.jboss.cache.aop.TreeCacheAopDelegate._putObject(TreeCacheAopDelegate.java:213)
      at org.jboss.cache.aop.TreeCacheAopDelegate._regularPutObject(TreeCacheAopDelegate.java:468)
      at org.jboss.cache.aop.TreeCacheAopDelegate._putObject(TreeCacheAopDelegate.java:206)
      at org.jboss.cache.aop.PojoCache._putObject(PojoCache.java:731)
      at org.jboss.cache.aop.PojoCache.putObject(PojoCache.java:462)
      at org.jboss.cache.aop.PojoCache.putObject(PojoCache.java:423)
      at com.gltrade.manager.cache.PojoCacheManagerImpl.put(PojoCacheManagerImpl.java:75)
      ... 12 more
      Caused by: java.lang.RuntimeException: javassist.CannotCompileException: by java.lang.VerifyError: class AOPClassProxy$0 overrides final method .Û8Ý*h'+
      at org.jboss.cache.aop.collection.CollectionInterceptorUtil.getMethodMap(CollectionInterceptorUtil.java:74)
      at org.jboss.cache.aop.collection.CachedMapInterceptor.(CachedMapInterceptor.java:33)
      at org.jboss.cache.aop.collection.CollectionInterceptorUtil.createMapProxy(CollectionInterceptorUtil.java:50)
      at org.jboss.cache.aop.CollectionClassHandler.collectionObjectPut(CollectionClassHandler.java:122)
      ... 19 more
      Caused by: javassist.CannotCompileException: by java.lang.VerifyError: class AOPClassProxy$0 overrides final method .Û8Ý*h'+
      at javassist.ClassPool.toClass(ClassPool.java:906)
      at javassist.ClassPool.toClass(ClassPool.java:846)
      at org.jboss.aop.AOPClassPool.toClass(AOPClassPool.java:181)
      at javassist.ClassPool.toClass(ClassPool.java:804)
      at javassist.CtClass.toClass(CtClass.java:1037)
      at org.jboss.aop.proxy.ClassProxyFactory.generateProxy(ClassProxyFactory.java:290)
      at org.jboss.aop.proxy.ClassProxyFactory.getProxyClass(ClassProxyFactory.java:67)
      at org.jboss.aop.proxy.ClassProxyFactory.newInstance(ClassProxyFactory.java:79)
      at org.jboss.aop.proxy.ClassProxyFactory.newInstance(ClassProxyFactory.java:52)
      at org.jboss.aop.proxy.ClassProxyFactory.newInstance(ClassProxyFactory.java:47)
      at org.jboss.cache.aop.collection.CollectionInterceptorUtil.getMethodMap(CollectionInterceptorUtil.java:72)
      ... 22 more
      Caused by: java.lang.VerifyError: class AOPClassProxy$0 overrides final method .Û8Ý*h'+
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:465)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at javassist.ClassPool.toClass(ClassPool.java:898)
      ... 32 more

      I have done many tests, I have reproduced the problem without Hibernate.
      In fact, the problem is the Hibernate implementation of Collections e.g: org.hibernate.collection.PersistentSet.

      When I create an Object which contains other objets within PersistentSet, I cannot put objets into PojoCache and I have the same exception.

      So, Could PojoCache work with Hibernate Objects and its Collection implementations ???

      Thanks for Help.

        • 1. Re: JBoss Cache (PojoCache) with Hibernate Collections (Pers
          Manik Surtani Master

          You should configure hibernate to use JBoss Cache as a 2nd level cache and handle the cachning of objects internally. You should not try and cache the objects yourself in this manner since this could potentially create a sitiation where you end up with stale data.

          See the chapter on caching in the hibernate docs for more details.

          • 2. Re: JBoss Cache (PojoCache) with Hibernate Collections (Pers
            Maxime Leur Newbie


            I correct this by recompile the class org.hibernate.collection.AbstractPersistentCollection without final method.

            I don't want tu use the 2nd level cache of hibernate, I want to use my onw cache and replicated it.

            But I have another blcking pb, When I called a method of my Set implementations which not belong to java.util.Set interface. I have an exception :

            java.lang.RuntimeException: CollectionInterceptorUtil.invoke(): targetObject is null. Can't invoke public boolean AOPClassProxy$0.setCurrentSession(org.hibernate.engine.SessionImplementor) throws org.hibernate.HibernateException
            at org.jboss.cache.aop.collection.CollectionInterceptorUtil.invoke(CollectionInterceptorUtil.java:144)
            at org.jboss.cache.aop.collection.CachedMapInterceptor.invoke(CachedMapInterceptor.java:117)
            at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
            at AOPClassProxy$0.setCurrentSession(AOPClassProxy$0.java)
            at org.hibernate.event.def.OnUpdateVisitor.processCollection(OnUpdateVisitor.java:40)
            at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:101)
            at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:61)
            at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:55)
            at org.hibernate.event.def.AbstractVisitor.process(AbstractVisitor.java:123)

            I have take a look in the code, and I don't understand why in or.jboss.aop.cache.collection.CollectionInterceptorUtil class the method getTargetObject on invocation object always return null ???

            In fact, I need some methods of my Set not be intercepted by AOP or just execute normally...

            Please Help me !

            • 3. Re: JBoss Cache (PojoCache) with Hibernate Collections (Pers
              Nitzan Niv Newbie

              The simple way to overcome the Hibernate collections' problem is to copy the contents of the collection in your object to a standard Java collection property before putting the object in the cache (e.g., in each setter method which Hibernate uses, replace the incoming Hibernate collection with a Java collection and store it in your object).
              Be aware that if you return the Java collection on the object's getter methods (which Hibernate uses), it makes the collection property "dirty" from Hibernate perspective, so the copied collections will probably be written back to the DB...

              • 4. Re: JBoss Cache (PojoCache) with Hibernate Collections (Pers
                Angus Morison Newbie

                I too am trying to persist Hibernate objects in the JBoss Cache, and I hit the same problem:

                java.lang.VerifyError: class AOPClassProxy$2 overrides final method

                I do not want to recompile Hibernate;
                I had originally tries Mark's suggestion of using JBC as the second level cache of Hibernate, but I hit the problem described here:http://www.jboss.org/index.html?module=bb&op=viewtopic&t=159042.
                Any suggrestions?

                • 5. Re: JBoss Cache (PojoCache) with Hibernate Collections (Pers
                  Galder Zamarreño Master

                  angusm, re: http://www.jboss.org/index.html?module=bb&op=viewtopic&t=159042, JBC is only supported as either read only or transactional cache, never read-write.