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