I ran into a problem while using hibernate4gwt. Basically beanlib is trying to instantiate an abstract superclass rather than concrete subclass so I get the following exception:
net.sf.beanlib.BeanlibException: java.lang.InstantiationException
at net.sf.beanlib.provider.replicator.BeanReplicator.replicateBean(BeanReplicator.java:99)
at net.sf.beanlib.provider.replicator.ReplicatorTemplate.replicateByBeanReplicatable(ReplicatorTemplate.java:115)
at net.sf.beanlib.provider.replicator.ReplicatorTemplate.replicate(ReplicatorTemplate.java:110)
at net.sf.beanlib.provider.BeanTransformer.transform(BeanTransformer.java:123)
at net.sf.beanlib.provider.BeanPopulator.doit(BeanPopulator.java:169)
at net.sf.beanlib.provider.BeanPopulator.processSetterMethod(BeanPopulator.java:133)
at net.sf.beanlib.provider.BeanPopulator.populate(BeanPopulator.java:104)
at net.sf.beanlib.provider.replicator.ReplicatorTemplate.populateBean(ReplicatorTemplate.java:160)
at net.sf.beanlib.provider.replicator.BeanReplicator.replicateBean(BeanReplicator.java:107)
at net.sf.beanlib.provider.replicator.ReplicatorTemplate.replicateByBeanReplicatable(ReplicatorTemplate.java:115)
at net.sf.beanlib.provider.replicator.ReplicatorTemplate.replicate(ReplicatorTemplate.java:110)
at net.sf.beanlib.provider.BeanTransformer.transform(BeanTransformer.java:123)
at net.sf.beanlib.hibernate.HibernateBeanReplicator.copy(HibernateBeanReplicator.java:77)
at net.sf.hibernate4gwt.core.LazyKiller.clone(LazyKiller.java:232)
I have done some investigation and believe I have found the problem in getUnEnhancer(…)in UnEnhancer.java. The method currently looks like:
@SuppressWarnings("unchecked")
public static <T> Class<T> getActualClass(Object proxy)
{
Class c = proxy.getClass();
boolean enhanced = true;
while (c != null && enhanced)
{
enhanced = Enhancer.isEnhanced(c);
if (!enhanced)
{
String className = c.getName();
// pattern found in javassist 3.4 and 3.6's ProxyFactory
enhanced = className.startsWith("org.javassist.tmp.")
|| className.indexOf("_$$_javassist_") != -1;
}
if (enhanced)
{
if ( proxy instanceof HibernateProxy ) {
HibernateProxy hibernateProxy = (HibernateProxy)proxy;
LazyInitializer lazyInitializer = hibernateProxy.getHibernateLazyInitializer();
return lazyInitializer.getPersistentClass(); *** This is the problem line ***
}
c = c.getSuperclass();
}
}
return (Class<T>)c;
}
getPersistentClass(…) returns the super class of the proxied type rather than the subclass. I think getPersistentClass() should be changed to getImplementation().getClass() to get the actually class that should be instantiated. I have tested this change and it works for my test case.
Thanks,
Chris
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am running into a problem with the beta15 release, I am using hibernate4gwt 1.0.4. Where an I get the source for beta15 so I can try a debug this problem. I can't upgrade to 17 as it doesn't seem to be compatible with hibernate4gwt 1.0.4.
Thanks,
Chris
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
>I can't upgrade to 17 as it doesn't seem to be compatible with hibernate4gwt 1.0.4.
Note beta17 has some critical bug fixes since beta15. Upgrading is strongly recommended. All the source is in the SVN repository. For beta15, it's under the branch:
I ran into a problem while using hibernate4gwt. Basically beanlib is trying to instantiate an abstract superclass rather than concrete subclass so I get the following exception:
net.sf.beanlib.BeanlibException: java.lang.InstantiationException
at net.sf.beanlib.provider.replicator.BeanReplicator.replicateBean(BeanReplicator.java:99)
at net.sf.beanlib.provider.replicator.ReplicatorTemplate.replicateByBeanReplicatable(ReplicatorTemplate.java:115)
at net.sf.beanlib.provider.replicator.ReplicatorTemplate.replicate(ReplicatorTemplate.java:110)
at net.sf.beanlib.provider.BeanTransformer.transform(BeanTransformer.java:123)
at net.sf.beanlib.provider.BeanPopulator.doit(BeanPopulator.java:169)
at net.sf.beanlib.provider.BeanPopulator.processSetterMethod(BeanPopulator.java:133)
at net.sf.beanlib.provider.BeanPopulator.populate(BeanPopulator.java:104)
at net.sf.beanlib.provider.replicator.ReplicatorTemplate.populateBean(ReplicatorTemplate.java:160)
at net.sf.beanlib.provider.replicator.BeanReplicator.replicateBean(BeanReplicator.java:107)
at net.sf.beanlib.provider.replicator.ReplicatorTemplate.replicateByBeanReplicatable(ReplicatorTemplate.java:115)
at net.sf.beanlib.provider.replicator.ReplicatorTemplate.replicate(ReplicatorTemplate.java:110)
at net.sf.beanlib.provider.BeanTransformer.transform(BeanTransformer.java:123)
at net.sf.beanlib.hibernate.HibernateBeanReplicator.copy(HibernateBeanReplicator.java:77)
at net.sf.hibernate4gwt.core.LazyKiller.clone(LazyKiller.java:232)
I have done some investigation and believe I have found the problem in getUnEnhancer(…)in UnEnhancer.java. The method currently looks like:
@SuppressWarnings("unchecked")
public static <T> Class<T> getActualClass(Object proxy)
{
Class c = proxy.getClass();
boolean enhanced = true;
while (c != null && enhanced)
{
enhanced = Enhancer.isEnhanced(c);
if (!enhanced)
{
String className = c.getName();
// pattern found in javassist 3.4 and 3.6's ProxyFactory
enhanced = className.startsWith("org.javassist.tmp.")
|| className.indexOf("_$$_javassist_") != -1;
}
if (enhanced)
{
if ( proxy instanceof HibernateProxy ) {
HibernateProxy hibernateProxy = (HibernateProxy)proxy;
LazyInitializer lazyInitializer = hibernateProxy.getHibernateLazyInitializer();
return lazyInitializer.getPersistentClass(); *** This is the problem line ***
}
c = c.getSuperclass();
}
}
return (Class<T>)c;
}
getPersistentClass(…) returns the super class of the proxied type rather than the subclass. I think getPersistentClass() should be changed to getImplementation().getClass() to get the actually class that should be instantiated. I have tested this change and it works for my test case.
Thanks,
Chris
Thanks for the suggestion. I have made the changes of trying to dig out the implementation class whenever possible. Please see the diff:
http://beanlib.svn.sourceforge.net/viewvc/beanlib/trunk/beanlib-hibernate/src/net/sf/beanlib/hibernate/UnEnhancer.java?r1=233&r2=241
You can now try out the beanlib-3.3.0beta15 release. Please let me know if any problem.
I have testing using beta15 and it has solved my problem.
Many Thanks,
Chris
I am running into a problem with the beta15 release, I am using hibernate4gwt 1.0.4. Where an I get the source for beta15 so I can try a debug this problem. I can't upgrade to 17 as it doesn't seem to be compatible with hibernate4gwt 1.0.4.
Thanks,
Chris
>I can't upgrade to 17 as it doesn't seem to be compatible with hibernate4gwt 1.0.4.
Note beta17 has some critical bug fixes since beta15. Upgrading is strongly recommended. All the source is in the SVN repository. For beta15, it's under the branch:
https://beanlib.svn.sourceforge.net/svnroot/beanlib/svntags/beanlib-3.3.0beta15