-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate 3 Issue with Classloaders
PostPosted: Sun May 06, 2007 10:24 am 
Newbie

Joined: Sun May 06, 2007 1:22 am
Posts: 2
We are in the process of building a server product that can be easily extended by the end user. To this end, we are using a classloader hierarchy internally to prevent libraries and classes from spilling over where we don't want them. We had successfully integrated several components that use classloaders internally until we got to hibernate 3 (this includes Spring, Tapestry and Jetty). For some reason, we can't seem to get Hibernate to start properly no matter what we try. Our hierarchy looks like this:

JVM Classloader
---Application Bootstrap Loader
------Database Loader <-- Hibernate and all it's supporting classes are here.
------Extension Loader <-- Custom extensions from users - it's at the same level as the database loader so no cross-over

Each loader is given it's parent so the chain is working properly and intact. This means that each child loader can access any classes from it's parent but the parent loaders don't have to worry about libraries needed by the children.

Our problem is this - We have a HibernateUtil class that we use to configure Hibernate for use. It is very simple. If we make this call:

sessionFactory = new Configuration().configure(configFile).buildSessionFactory();

We get this exception:

Initial SessionFactory creation failed.net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.xxx.xxx.servers.db.hibernate.HibernateUtil.start(HibernateUtil.java:48)
at com.xxx.xxx.servers.db.derby.DerbyEngine.init(DerbyEngine.java:28)
at com.xxx.xxx.servers.db.DatabaseServerWrapper.init(DatabaseServerWrapper.java:71)
at com.xxx.xxx.servers.registry.RegistryServer.init(RegistryServer.java:128)
at com.xxx.xxx.servers.standalone.StandaloneServer.<init>(StandaloneServer.java:30)
at com.xxx.xxx.factories.StandaloneServerFactory.buildStandaloneServer(StandaloneServerFactory.java:13)
at com.xxx.xxx.factories.ServerFactory.buildStandaloneServer(ServerFactory.java:44)
at com.xxx.xxx.Main.startUp(Main.java:124)
at com.xxx.xxx.Main.processCommandLineResults(Main.java:289)
at com.xxx.xxx.Main.invoke(Main.java:245)
at com.xxx.xxx.bootstrap.Main.main(Main.java:68)
Caused by: net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:237)
at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
at net.sf.cglib.proxy.Enhancer.createClass(Enhancer.java:317)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:127)
at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:43)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:162)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:135)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:295)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at com.xxx.xxx.servers.db.hibernate.HibernateUtil.start(HibernateUtil.java:41)
... 10 more
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:597)
at net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:384)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:219)
... 25 more
Caused by: java.lang.NoClassDefFoundError: org/hibernate/proxy/HibernateProxy
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
... 31 more


We decided to check and ensure that the current loader has org/hibernate/proxy/HibernateProxy in it, so we run this code right before:

System.err.println(HibernateUtil.class.getClassLoader().loadClass("org.hibernate.proxy.HibernateProxy"));
System.err.println(Thread.currentThread().getContextClassLoader().loadClass("org.hibernate.proxy.HibernateProxy"));

It prints out "interface org.hibernate.proxy.HibernateProxy" two times, which tells us that both the current classes' loader and the current context loader both have access to the jar. In our experience, ensuring that both of these are set correctly is all it's taken to get past classloader issues. How do we solve this problem? What is Hibernate/CGLib doing under the covers that it can't find the class when every accessible classloader has it. We want to use Hibernate but this is driving us crazy and preventing us from proceeding. Thanks!

Mike


Top
 Profile  
 
 Post subject: RE: Hibernate 3 Issue with Classloaders
PostPosted: Tue May 08, 2007 9:52 am 
Newbie

Joined: Tue May 08, 2007 9:43 am
Posts: 1
Hi Mike,

I had the same problem like you and fixed it like mentioned here:
http://dev.eclipse.org/newslists/news.e ... 02551.html

The Problem isn't the HibernateProxy itself,its that the Proxy trying to proxy one of you classes and fails loading it! You can see on which class he fails, if you, in debug mode, set an breakpoint on InvocationTargetException (did it in eclipse).

hope this helps.

cn


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 08, 2007 10:29 am 
Newbie

Joined: Sun May 06, 2007 1:22 am
Posts: 2
Thanks for the help CN. I suspect you are correct but this problem happened to be the last staw. Fed up with hard to diagnose and debug problems with Hibernate, I switched the project over to iBatis yesterday. Took all of about 2 hours to get it done and it didn't have any quirky behavior at all. Everything just worked the first time out.

I'll still use Hibernate inside of Spring for some things but I think I'm going to switch to iBatis for most applications.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.