-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Problem with CGLIB: NoClassDefFoundError
PostPosted: Fri Jan 28, 2005 8:02 am 
Regular
Regular

Joined: Fri Sep 17, 2004 10:51 am
Posts: 61
Location: Rimini, Italy
Hi there, I'm trying to use Hibernate3 beta 2 for a new module of my project, but I get this warn in the log:

Code:
2005-01-27 17:20:11,705 [ApplicationServerThread] WARN  org.hibernate.persister.AbstractEntityPersister - could not create proxy class
for:cinetica.nannucci.ejb.catalog.ArticoloData
org.hibernate.HibernateException: CGLIB Enhancement failed: cinetica.nannucci.ejb.catalog.ArticoloData
        at org.hibernate.proxy.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:90)
        at org.hibernate.proxy.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:38)
        at org.hibernate.persister.AbstractEntityPersister.<init>(AbstractEntityPersister.java:458)
        at org.hibernate.persister.BasicEntityPersister.<init>(BasicEntityPersister.java:352)
        at org.hibernate.persister.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:95)
        at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:44)
        at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:196)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1031)
        at cinetica.nannucci.web.component.PersistenceManagerFactory.init(PersistenceManagerFactory.java:32)
        at com.opensymphony.xwork.interceptor.component.DefaultComponentManager.loadResource(DefaultComponentManager.java:154)
        at com.opensymphony.xwork.interceptor.component.DefaultComponentManager.loadResource(DefaultComponentManager.java:139)
        at com.opensymphony.xwork.interceptor.component.DefaultComponentManager.loadResource(DefaultComponentManager.java:139)
        at com.opensymphony.xwork.interceptor.component.DefaultComponentManager.initializeObject(DefaultComponentManager.java:75)
        at com.opensymphony.xwork.interceptor.component.ComponentInterceptor.before(ComponentInterceptor.java:29)
        at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:34)
        at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:166)
        at com.opensymphony.xwork.DefaultActionProxy.execute(DefaultActionProxy.java:115)
        at com.opensymphony.webwork.dispatcher.ServletDispatcher.serviceAction(ServletDispatcher.java:278)
        at com.opensymphony.webwork.dispatcher.ServletDispatcher.service(ServletDispatcher.java:248)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:336)
        at com.evermind._ha.doFilter(Unknown Source)
        at com.opensymphony.webwork.lifecycle.RequestLifecycleFilter.doFilter(RequestLifecycleFilter.java:75)
        at com.evermind._gz.doFilter(Unknown Source)
        at cinetica.nannucci.web.filter.FilterAdapter.doFilter(FilterAdapter.java:27)
        at com.evermind._ctb._psd(Unknown Source)
        at com.evermind._ctb._bqc(Unknown Source)
        at com.evermind._ax._luc(Unknown Source)
        at com.evermind._ax._ucb(Unknown Source)
        at com.evermind._bf.run(Unknown Source)
Caused by: net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
        at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:236)
        at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:368)
        at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:280)
        at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:597)
        at org.hibernate.proxy.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:76)
        ... 28 more
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.GeneratedMethodAccessor87.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:373)
        at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:218)
        ... 32 more
Caused by: java.lang.NoClassDefFoundError: org/hibernate/proxy/HibernateProxy
        at java.lang.ClassLoader.defineClass0(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
        ... 37 more


I've used all the libs found in the Hibernate3 package, following the dependecies of the docs:
    - ehcache-1.1.jar
    - commons-logging-1.0.4.jar
    - dom4j-1.5.2.jar
    - antlr-2.7.4.jar
    - cglib-full-2.0.2.jar
    - commons-collections-2.1.1.jar


I'm using WebWork 2, with the HibernateInterceptor written by G.King for the previous version of Hibernate and adapted to the new one (package renamed). I'm using an Oracle 9.2.0.5 DB.
I get no error for the mapping documents.
Any idea ?
TIA

_________________
--
Marco


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 29, 2005 12:30 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
This deployment problem, cglib can not find hibernate classes

java.lang.NoClassDefFoundError: org/hibernate/proxy/HibernateProxy

Generated proxy depends on this class.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 31, 2005 5:13 am 
Regular
Regular

Joined: Fri Sep 17, 2004 10:51 am
Posts: 61
Location: Rimini, Italy
Thanks for Your reply. I've figured this out, but the strange thing is that I placed the hibernate3.jar (which contains the proxy class) in the WEB-INF/lib dir of the web app, and I know the hibernate jar is used 'cause Hibernate is correctly initialized. I get the error as soon as I try to execute a query.
Is it possible that hibernate can call GClib and GClib can't see hibernate classes ?

_________________
--
Marco


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 03, 2005 2:10 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Try to reproduce it using MyClass.class.getClassLoader().load("org.hibernate.proxy.HibernateProxy")
Probably it will help to find problem (it can be more usefull stuff on stack).
This class loader must see your domain classes, hibernate and cglib classes, but "NoClassDefFoundError" can be caused by "ExceptionInInitilizerError", "LinkegeError" or "VerificationError" (JVM throws this error if you are trieng to load not existing or "dead" class, it becomes "dead" if the first attemt to load, resolve, link and initilize fails ).


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 19, 2005 4:50 am 
Newbie

Joined: Thu May 19, 2005 4:09 am
Posts: 2
Hello, I am also getting the same cause: java.lang.NoClassDefFoundError: org/hibernate/proxy/HibernateProxy from CGLIB.

My application is middleware which uses classloaders for hot redeployment of applications as well as hiding server implementation from hosted application. Hierarchy of classloaders:
- ServerClassloader - holds hibernate.jar, cglib.jar, ... and some system VOs. Hibernate is handled from this place.
- AppClassloader - holds application VOs
- SharedClassloader - parent of previous classloaders

During initialization of Hibernate ApplicationClassloader is set as context classloader (the same applies every time application does anything with Hibernate).

Maybe it looks a bit complicated, but it worked perfectly with 2.1.x. I was forced to move to 3.0.3 because of Websphere 6.0 support and now it refuses to initialize Hibernate with this exception.

If I move all JARs needed by Hibernate to SharedClassloader, I will not see VOs in ServerClassloader, of course.

I would like to ask, if something was changed regarding classloaders (plus usage of context classloader) during initialization, especially when CGLIB is used (I tried 2.1 and also one comming with old Hibernate, thus they probably did not change it). Do you have any other idea why it might not work? Could you navigate me to particular sources I could check myself, please? Any pointers are really appreciated.

I am using Java 1.5, Win.

Thank you very much!
Pavol


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 19, 2005 11:09 am 
Newbie

Joined: Thu May 19, 2005 4:09 am
Posts: 2
Well, I found workaroud for my problem. I set default-lazy="false" for those VOs that are loaded from AppClassloader (see my previous post).

I found this solution by logging what classes are defined in AbstractClassGenerator and I found Hibernate 2.1.8 generates ...$$FastClassByCGLIB and ...$$BulkBeanByCGLIB while 3.0.3 generates ...$$FastClassByCGLIB and ...$$EnhancerByCGLIB. This Enhancer stuff fails when VOs belong to AppClassloader.

It seems class loaders are handled differently when Enhanced stuff is defined compared to BulkBean and FastClass.
I'd like to ask if this might be bug in CGLIB or whwether you know this is feature, because I do not orient there much yet. What do you think?

Cheers,
Pavol


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 16, 2005 6:00 pm 
Newbie

Joined: Thu Jun 16, 2005 5:21 pm
Posts: 6
I'm hitting a similar issue in a configuration not unlike Pavol's.

Simplifying slightly, I have Hibernate 3.0.5 packaged in an Eclipse 3.0.1 plugin. I then have my application code in another plugin that imports the hibernate plugin. This puts hibernate in a child class loader of my application's class loader.

I set the context class loader to my application's class loader before calling buildSessionFactory(new Configuration().configure()) in my application initialization code.

My code works "fine", but I get an error logged during the call to configure() - everything carries on and ignores the error, with my objects being correctly persisted. Note my error is similar, but not identical, to the warning reported above. I've appended the error below.

As Pavol found, adding default-lazy="false" to my mapping documents causes the error to go away.

Any comments appreciated on whether adding default-lazy="false" is the right thing to do in this class loader configuration, or whether I should be coding this differently, or whether perhaps there's an issue in cglib with class loaders?

TIA.

Olli
===
Code:
Time: 1:38:54 PM  Priority: ERROR  Thread: main  NDC: null
Category: org.hibernate.proxy.BasicLazyInitializer
Location: null
Message:
CGLIB Enhancement failed: com.generic.emr.model.Metric
Throwable:
net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
   at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:236)
   at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:373)
   at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:281)
   at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:640)
   at org.hibernate.proxy.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:94)
   at org.hibernate.proxy.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:42)
   at org.hibernate.tuple.PojoTuplizer.buildProxyFactory(PojoTuplizer.java:144)
   at org.hibernate.tuple.AbstractTuplizer.<init>(AbstractTuplizer.java:83)
   at org.hibernate.tuple.PojoTuplizer.<init>(PojoTuplizer.java:54)
   at org.hibernate.tuple.TuplizerLookup.create(TuplizerLookup.java:47)
   at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:218)
   at org.hibernate.persister.entity.BasicEntityPersister.<init>(BasicEntityPersister.java:400)
   at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:104)
   at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
   at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:211)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1005)
   at com.generic.emr.data.HibernateUtils.buildSessionFactory(HibernateUtils.java:88)
   at com.generic.emr.data.HibernateUtils.<clinit>(HibernateUtils.java:41)
   at com.generic.emr.data.DBTables.dropAndCreate(DBTables.java:36)
   at com.generic.emr.mbeans.Repository.dropAndRecreateNewEmptyTablesInRepository(Repository.java:147)
   at com.generic.emr.mbeans.Repository.<init>(Repository.java:70)
   at com.generic.emr.mbeans.LocalListener.<init>(LocalListener.java:42)
   at com.generic.emr.mbeans.RepositoryWriter.<init>(RepositoryWriter.java:66)
   at com.generic.emr.EMRService.run(EMRService.java:56)
   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:324)
   at com.generic.agent.services.ServiceHandler.invokeOperation(ServiceHandler.java:200)
   at com.generic.agent.services.ServiceHandler.startServices(ServiceHandler.java:110)
   at com.generic.agent.Global.initializeDomainModel(Global.java:105)
   at com.generic.agent.Agent.main(Agent.java:334)
   at com.generic.agent.Agent.run(Agent.java:93)
   at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:335)
   at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:273)
   at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:129)
   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:324)
   at org.eclipse.core.launcher.Main.basicRun(Main.java:185)
   at org.eclipse.core.launcher.Main.run(Main.java:704)
   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:324)
   at com.generic.agent.Startup.invokeNextMain(Startup.java:59)
   at com.generic.agent.Startup.main(Startup.java:34)
   Caused by: java.lang.reflect.InvocationTargetException
   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:324)
   at net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:373)
   at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:218)
   ... 47 more
   Caused by: java.lang.NoClassDefFoundError: net/sf/cglib/proxy/Factory
   at java.lang.ClassLoader.defineClass0(Native Method)
   at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
   ... 53 more


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 4:29 pm 
Newbie

Joined: Mon Nov 14, 2005 4:24 pm
Posts: 1
Location: www.ccsinventory.com
ohpb2003 wrote:
I'm hitting a similar issue in a configuration not unlike Pavol's.

Simplifying slightly, I have Hibernate 3.0.5 packaged in an Eclipse 3.0.1 plugin. I then have my application code in another plugin that imports the hibernate plugin. This puts hibernate in a child class loader of my application's class loader.

*snip*

As Pavol found, adding default-lazy="false" to my mapping documents causes the error to go away.

Any comments appreciated on whether adding default-lazy="false" is the right thing to do in this class loader configuration, or whether I should be coding this differently, or whether perhaps there's an issue in cglib with class loaders?

TIA.

Olli
===
Code:
        *snip*
   Caused by: java.lang.NoClassDefFoundError: net/sf/cglib/proxy/Factory
   at java.lang.ClassLoader.defineClass0(Native Method)
   at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
   ... 53 more


I just figured this out as I was having the same problem. Make sure that the plugin that contains net.sf.cglib also exports the following packages in the MANIFEST.MF file:

Export-Package: net.sf.cglib.proxy,
net.sf.cglib.core,
net.sf.cglib.reflect

It seems something about the proxy reflection needs these to be available outside of the hibernate plugin.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.