Menu

Javassist proxy issue

Help
2007-08-23
2013-04-25
  • Bruno Marchesson

    Hello,

    I found an issue when cloning a Javassist proxyfied Hibernate POJO with HibernateBeanReplicator.
    The clone result still have proxies (such as User_$$javassist_0), whereas I expected it to have cloned the underlying class as it is the case with CGLIB.

    After some debug, It seems that the problem comes from the Hibernate3JavaBeanReplicator class : in the 'createToInstance' method, the CGLIB proxy is explicitly handled, but not javassist one.
    I modified my local beanLib sources with the following code :

    protected <T> T createToInstance(Class<T> toClass)
            throws InstantiationException, IllegalAccessException, SecurityException, NoSuchMethodException
    {
        if (Enhancer.isEnhanced(toClass) ||
            toClass.getName().contains("_$$_javassist_")) {
            // figure out the pre-enhanced class
            toClass = (Class<T>)toClass.getSuperclass();
        }
           
        return super.createToInstance(toClass);
    }

    And it works now.
    Do you think my understanding is right ?

    Regards
    Bruno

     
    • Hanson Char

      Hanson Char - 2007-08-23

      Interesting.  Admittedly I haven't worked with Javassist enhanced objects in Hibernate, so I don't know if your proposal is a general solution.  Currently on vacation, I'll look into this when I'm back after Sep 5th.  Thanks!

       
    • Bruno Marchesson

      Hello Hanson,

      Did you have a look on it ?

      Regards
      Bruno

       
      • Hanson Char

        Hanson Char - 2007-09-18

        In javassist 3.4 and 3.6, and the ProxyFactory has code like:

            private static synchronized String makeProxyName(String classname) {
                return classname + "_$$_javassist_" + counter++;
            }
        ...
                classname = makeProxyName(classname);
                if (classname.startsWith("java."))
                    classname = "org.javassist.tmp." + classname;
        ...
        So it seems we can either match the pattern "_$$_javassist_" or check the prefix "org.javassist.tmp." in the class name to see if it has been javassist-enhanced.

         
      • Hanson Char

        Hanson Char - 2007-09-18

        Hi Bruno,

        Can you do me a favor ?  Download and try out the 3.3.0beta10 release I've tentatively made:

          http://sourceforge.net/project/showfiles.php?group_id=140152&package_id=170678&release_id=540466

        and see if that would work for you ?  Thanks in advance.

         
        • Bruno Marchesson

          Hello Hanson,

          I tried it this morning and it works perfectly :)

          Thanks
          Bruno

           

Log in to post a comment.