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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
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!
Hello Hanson,
Did you have a look on it ?
Regards
Bruno
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.
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.
Hello Hanson,
I tried it this morning and it works perfectly :)
Thanks
Bruno