From: <leg...@at...> - 2004-08-05 14:25:04
|
The following comment has been added to this issue: Author: Francois Beausoleil Created: Thu, 5 Aug 2004 9:49 AM Body: Okay, Christian, I'm following the quickstart right now. Downloaded Tomcat 4.1.30 and Hibernate 2.1.4. mkdir E:\quickstart jar xf jakarta-tomcat-4.1.30.zip jar xf hibernate-2.1.zip copy hibernate-2.1\lib\hsqldb.jar jakarta-tomcat-4.1.30\common\lib mkdir jakarta-tomcat-4.1.30\webapps\quickstart\WEB-INF\lib copy hibernate-2.1\hibernate2.jar jakarta-tomcat-4.1.30\webapps\quick= start\WEB-INF\lib copy hibernate-2.1\lib\dom4j-1.4.jar jakarta-tomcat-4.1.30\webapps\qu= ickstart\WEB-INF\lib copy hibernate-2.1\lib\cglib-full-2.0.1.jar jakarta-tomcat-4.1.30\web= apps\quickstart\WEB-INF\lib copy hibernate-2.1\lib\commons-collections-2.1.jar jakarta-tomcat-4.1= .30\webapps\quickstart\WEB-INF\lib copy hibernate-2.1\lib\commons-logging-1.0.3.jar jakarta-tomcat-4.1.3= 0\webapps\quickstart\WEB-INF\lib copy hibernate-2.1\lib\ehcache-0.7.jar jakarta-tomcat-4.1.30\webapps\= quickstart\WEB-INF\lib Edit jakarta-tomcat-4.1.30\conf\server.xml Copied the Context configuration verbatim from step 1.1 of the quicks= tart Edited the Context to use HSQLDB instead: <Context path=3D"/quickstart" docBase=3D"quickstart"> ... <!-- DBCP database connection settings --> <parameter> <name>url</name> <value>jdbc:hsqldb:hsql://localhost</value> </parameter> <parameter> <name>driverClassName</name><value>org.hsqldb.jdbcDriver</value= > </parameter> <parameter> <name>username</name> <value>sa</value> </parameter> <parameter> <name>password</name> <value></value> </parameter> ... </Context> mkdir jakarta-tomcat-4.1.30\webapps\quickstart\WEB-INF\classes Edit jakarta-tomcat-4.1.30\webapps\quickstart\WEB-INF\classes\hiberna= te.cfg.xml and copied the configuration. Changed the dialect to use HSQL: <property name=3D"dialect">net.sf.hibernate.dialect.HSQLDialect</pr= operty> mkdir jakarta-tomcat-4.1.30\webapps\quickstart\WEB-INF\classes\net\sf= \hibernate\examples\quickstart Created jakarta-tomcat-4.1.30\webapps\quickstart\WEB-INF\classes\hibe= rnate.cfg.xml Created jakarta-tomcat-4.1.30\webapps\quickstart\WEB-INF\classes\net\= sf\hibernate\examples\quickstart\Cat.java Created jakarta-tomcat-4.1.30\webapps\quickstart\WEB-INF\classes\Cat.= hbm.xml Those last three were copied verbatim from the quickstart guide. Created jakarta-tomcat-4.1.30\webapps\quickstart\WEB-INF\classes\net\= sf\hibernate\examples\quickstart\HibernateUtil.java Copied verbatim from the quickstart guide. Created jakarta-tomcat-4.1.30\webapps\quickstart\WEB-INF\classes\net\= sf\hibernate\examples\quickstart\HibernateServlet.java package net.sf.hibernate.examples.quickstart; import javax.servlet.*; import javax.servlet.http.*; import net.sf.hibernate.*; import java.io.*; public class HibernateServlet extends HttpServlet { public void init() { try { Session session =3D HibernateUtil.currentSession(); Transaction tx=3D session.beginTransaction(); Cat princess =3D new Cat(); princess.setName("Princess"); princess.setSex('F'); princess.setWeight(7.4f); session.save(princess); tx.commit(); HibernateUtil.closeSession(); } catch (HibernateException e) { e.printStackTrace(); } } public void doGet(HttpServletRequest request, HttpServletResponse respo= nse) throws ServletException { try { response.setContentType("text/plain"); response.getWriter().println("Getting !"); } catch (IOException e) { e.printStackTrace(); } } } Created jakarta-tomcat-4.1.30\webapps\quickstart\WEB-INF\web.xml <?xml version=3D"1.0" encoding=3D"ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <servlet> <servlet-name>princess-creator</servlet-name> <servlet-class>net.sf.hibernate.examples.quickstart.HibernateServle= t</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>princess-creator</servlet-name> <url-pattern>/princess.html</url-pattern> </servlet-mapping> </web-app> set CATALINA_HOME=3DE:\quickstart\jakarta-tomcat-4.1.30 Started HSQLDB Server Started Tomcat Visited http://localhost:8080/quickstart/princess.html Confirmed that the servlet was working =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Starting from now, I change the config slightly: Shutdown everything (HSQLDB, Tomcat) Delete the HSQLDB db directory Restart the HSQLDB server Create new DB schema like this: create table CAT ( cat_id char(32) primary key, name varchar(16) not null, sex char(1), weight real, personal varchar(80), email varchar(240) ); Add a mapping for E-Mail address to Cat.hbm.xml: <component name=3D"address"> <property name=3D"personal" length=3D"80"/> <property name=3D"address" length=3D"240"/> </component> Update Cat.java to add the following: private InternetAddress address; public void setAddress(InternetAddress address) { this.address =3D address; } public InternetAddress getAddress() { return address; } *** Recompiled *** Restart Tomcat *** Confirm exception received: 2004-08-05 10:12:23 net.sf.hibernate.cfg.Configuration addInputStream GRAVE: Could not configure datastore from input stream net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTarg= etException-->null at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGen= erator.java:208) at net.sf.cglib.reflect.FastClass$Generator.create(FastClass.java:9= 2) at net.sf.cglib.reflect.FastClass.create(FastClass.java:74) at net.sf.hibernate.type.ComponentType.<init>(ComponentType.java:11= 3) at net.sf.hibernate.cfg.Binder.bindComponent(Binder.java:899) ... Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessor= Impl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethod= AccessorImpl.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(AbstractClassGen= erator.java:195) ... 35 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) ... 41 more As you can see, I have the exact same exception. Has anyone tried mapping = an InternetAddress ? The quickstart above is using the mail.jar and activation.jar distributed w= ith Tomcat 4.1.30. As noted above, I copied cglib distributed with Hiberna= te 2.1.4. Christian, I've now shown you *twice* that I can get the NoClassDefError. = Both times, I've done it with fresh installs of Tomcat and Hibernate. Maybe you can show me a bit more consideration this time, and tell me where= I'm going wrong ? Is it in my mapping of the InternetAddress ? Am I doin= g something wrong in the quickstart ? Did I forget a step ? Bye, Fran=C3=A7ois --------------------------------------------------------------------- View this comment: http://opensource.atlassian.com/projects/hibernate/browse/HB-1064?page=3D= comments#action_13940 --------------------------------------------------------------------- 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: Closed Priority: Minor Resolution: REJECTED Original Estimate: 5 minutes Time Spent: Unknown Remaining: 5 minutes Project: Hibernate2 Components:=20 core Versions: 2.1.3 Assignee:=20 Reporter: Tim Motika Created: Mon, 5 Jul 2004 6:35 AM Updated: Thu, 5 Aug 2004 9:49 AM Environment: All; ( win32 resin / issue when cglib dynamically loaded and n= ot 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 fo= r some container-related reason (CGLib is probably using Class.forName() wh= ich only loads system classes instead of getClass.getClassLoader().loadClas= s() ). Container behavior aside, Hibernate is breaking encapsulation by loading cg= lib 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().loa= dClass() 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 i= s 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.use= ReflectionOptimizer() returns false. Error: net.sf.cglib.core.CodeGenerationException: java.lang.reflect.Invocat= ionTargetException-->null net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTarg= etException-->null =09at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerato= r.java:208) =09at net.sf.cglib.reflect.FastClass$Generator.create(FastClass.java:92) =09at net.sf.cglib.reflect.FastClass.create(FastClass.java:74) =09at net.sf.hibernate.persister.AbstractEntityPersister.(AbstractEntityPer= sister.java:756) =09at net.sf.hibernate.persister.EntityPersister.(EntityPersister.java:714) =09at net.sf.hibernate.persister.PersisterFactory.createClassPersister(Pers= isterFactory.java:42) =09at net.sf.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:137= ) =09at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.= java:768) =09at org.tlala.site.HibernateUtil.start(HibernateUtil.java:183) =09at org.tlala.site.DBHome.startDB(DBHome.java:86) =09at org.tlala.site.DBHome.currentSession(DBHome.java:145) =09at org.tlala.site.DBHome.doBody(DBHome.java:292) =09at org.tlala.site.DBHome.service(DBHome.java:215) =09at org.tlala.site.DBHome.service(DBHome.java:176) =09at com.caucho.server.http.FilterChainServlet.doFilter(FilterChainServlet= .java:96) =09at com.caucho.server.http.Invocation.service(Invocation.java:315) =09at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:1= 35) =09at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:246= ) =09at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:= 164) =09at com.caucho.server.TcpConnection.run(TcpConnection.java:139) =09at java.lang.Thread.run(Thread.java:534) Caused by: java.lang.reflect.InvocationTargetException =09at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) =09at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.= java:39) =09at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces= sorImpl.java:25) =09at java.lang.reflect.Method.invoke(Method.java:324) =09at net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:411) =09at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerato= r.java:195) =09... 20 more Caused by: java.lang.NoClassDefFoundError: net/sf/cglib/reflect/FastClass =09at java.lang.ClassLoader.defineClass0(Native Method) =09at java.lang.ClassLoader.defineClass(ClassLoader.java:537) =09... 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 |