From: <leg...@at...> - 2004-08-05 21:39:54
|
The following comment has been added to this issue: Author: Max Rydahl Andersen Created: Thu, 5 Aug 2004 5:04 PM Body: Google is great ;) http://sourceforge.net/forum/message.php?msg_id=1720229 The original thread were me and my colleague pointed out the exact same problem. I think only hibernate admins can read that posting from the forum so i'm also pasting it here: "The "most correct" way to load a class in either J2EE or J2SE is to follow the pattern defined in the class below. This allows class loading to work properly in a context where there are more than one classloader (such as inside an app server). --- public class ClassUtil { static Class forName(String name) throws ClassNotFoundException { ClassLoader ctxLoader = null; try { ctxLoader = Thread.currentThread() .getContextClassLoader(); return Class.forName(name, true, ctxLoader); } catch(ClassNotFoundException ex) { if(ctxLoader == null) { throw ex; } } catch(SecurityException ex) { } return Class.forName(name); } } --- For the second Class.forName to have any effect, the ClassUtil class should be loaded using the same class loader as the caller of this function. Therefore, this class should be included in the same linkage unit (class path element, .jar file or whatever) as the calling code. And thus; this class is (unfortunately) not really a good candidate to go into a generic class library. At this point, most of the code in the JDK follows this pattern, but there are still many libraries out there that don't. This means that such libraries may not work correctly in a situation with more than one class loader." --------------------------------------------------------------------- View this comment: http://opensource.atlassian.com/projects/hibernate/browse/HB-1064?page=comments#action_13948 --------------------------------------------------------------------- View the issue: http://opensource.atlassian.com/projects/hibernate/browse/HB-1064 Here is an overview of the issue: --------------------------------------------------------------------- Key: HB-1064 Summary: CGLIB classes loaded even when reflection optimizer disabled Type: Bug Status: Reopened Priority: Minor Original Estimate: 5 minutes Time Spent: Unknown Remaining: 5 minutes Project: Hibernate2 Components: core Versions: 2.1.3 Assignee: Gavin King Reporter: Tim Motika Created: Mon, 5 Jul 2004 6:35 AM Updated: Thu, 5 Aug 2004 5:04 PM Environment: All; ( win32 resin / issue when cglib dynamically loaded and not in system classpath, as on a webapp) Description: Running Hibernate from a webapp causes crash on ClassNotFoundException with the cglib in the lib/ non-system path, even when the optimizer is turned off, since it fails, being unable to load net.sf.cglib.reflect.FastClass for some container-related reason (CGLib is probably using Class.forName() which only loads system classes instead of getClass.getClassLoader().loadClass() ). Container behavior aside, Hibernate is breaking encapsulation by loading cglib even when the feature is turned off, then not using it. Suggested fix: Only execute the calls to FastClass.create() conditionally in these three files: ./net/sf/hibernate/persister/AbstractEntityPersister.java:756 ./net/sf/hibernate/type/ComponentType.java:113 ./net/sf/hibernate/util/ReflectHelper.java:156 Related: change usage of Class.forName() to getClass().getClassLoader().loadClass() in CGLIB so that the jar is not pinned to being in the system classpath Hrm. Environmnet is *only* used in these files to check if the optimizer is on. Seems like moving them over to configuration-based checking would be possible. BTW, thanks for the great work on Hibernate! Autopsy: Stack trace, even when the optimizer has been disabled, and Environment.useReflectionOptimizer() returns false. Error: net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:208) at net.sf.cglib.reflect.FastClass$Generator.create(FastClass.java:92) at net.sf.cglib.reflect.FastClass.create(FastClass.java:74) at net.sf.hibernate.persister.AbstractEntityPersister.(AbstractEntityPersister.java:756) at net.sf.hibernate.persister.EntityPersister.(EntityPersister.java:714) at net.sf.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:42) at net.sf.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:137) at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:768) at org.tlala.site.HibernateUtil.start(HibernateUtil.java:183) at org.tlala.site.DBHome.startDB(DBHome.java:86) at org.tlala.site.DBHome.currentSession(DBHome.java:145) at org.tlala.site.DBHome.doBody(DBHome.java:292) at org.tlala.site.DBHome.service(DBHome.java:215) at org.tlala.site.DBHome.service(DBHome.java:176) at com.caucho.server.http.FilterChainServlet.doFilter(FilterChainServlet.java:96) at com.caucho.server.http.Invocation.service(Invocation.java:315) at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135) at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:246) at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:164) at com.caucho.server.TcpConnection.run(TcpConnection.java:139) at java.lang.Thread.run(Thread.java:534) 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:411) at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:195) ... 20 more Caused by: java.lang.NoClassDefFoundError: net/sf/cglib/reflect/FastClass at java.lang.ClassLoader.defineClass0(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:537) ... 26 more --------------------------------------------------------------------- JIRA INFORMATION: This message is automatically generated by JIRA. If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa If you want more information on JIRA, or have a bug to report see: http://www.atlassian.com/software/jira |