Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Hibernate Tutorial Chapter 1 cglib NoClassDefFoundError
PostPosted: Sat Jun 28, 2008 2:52 pm 
Newbie

Joined: Sat Jun 28, 2008 2:09 pm
Posts: 2
I'm working through chapter 1 of the tutorial using MySQL instead of HSQL since I'll end up using MySQL and I've used it a bit already. When I execute "ant run -Daction=post" everything looks fine until I try to get a session factory. Then it fails with the following error:

Code:
Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: net.sf.cglib.core.DebuggingClassWriter$1


I've verified that cglib-2.1.3.jar is in my lib/ directory with all of the other jar files used for this example. I've also verified that the net.sf.cglib.core.DebuggingClassWriter$1.class file is in that jar.

The version of java installed on my system is:
Code:
[erturne@hsd1 src]$ java -version
java version "1.6.0"
OpenJDK  Runtime Environment (build 1.6.0-b09)
OpenJDK 64-Bit Server VM (build 1.6.0-b09, mixed mode)
[erturne@hsd1 src]$ javac -version
Eclipse Java Compiler 0.793_R33x, 3.3.2, Copyright IBM Corp 2000, 2008. All rights reserved.


Any suggestions on what else to look for?

My ant build.xml file
Code:
<project name="hibernate-tutorial" default="compile">

  <property name="sourcedir" value="${basedir}/src" />
  <property name="targetdir" value="${basedir}/bin" />
  <property name="librarydir" value="${basedir}/lib" />

  <path id="libraries">
    <fileset dir="${librarydir}">
      <include name="*.jar"/>
    </fileset>
  </path>

  <target name="clean">
    <delete dir="${targetdir}"/>
    <mkdir dir="${targetdir}"/>
  </target>

  <target name="compile" depends="clean, copy-resources">
    <javac srcdir="${sourcedir}"
      destdir="${targetdir}"
      classpathref="libraries"/>
  </target>
 
  <target name="copy-resources">
    <copy todir="${targetdir}">
      <fileset dir="${sourcedir}">
   <exclude name="**/*.java"/>
      </fileset>
    </copy>
  </target>

  <target name="run" depends="compile">
    <java fork="true" classname="events.EventManager" classpathref="libraries">
      <classpath path="${targetdir}"/>
      <arg value="${action}"/>
    </java>
  </target>

</project>



Here's the full trace:
Code:
     [java] 14:29:34,800  INFO Environment:514 - Hibernate 3.2.6
     [java] 14:29:34,891  INFO Environment:547 - hibernate.properties not found
     [java] 14:29:34,904  INFO Environment:681 - Bytecode provider name : cglib
     [java] 14:29:35,004  INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling
     [java] 14:29:35,105  INFO Configuration:1432 - configuring from resource: /hibernate.cfg.xml
     [java] 14:29:35,107  INFO Configuration:1409 - Configuration resource: /hibernate.cfg.xml
     [java] 14:29:35,586  INFO Configuration:559 - Reading mappings from resource : events/Event.hbm.xml
     [java] 14:29:35,882  INFO HbmBinder:300 - Mapping class: events.Event -> EVENTS
     [java] 14:29:35,946  INFO Configuration:1547 - Configured SessionFactory: null
     [java] 14:29:36,114  INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
     [java] 14:29:36,116  INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 1
     [java] 14:29:36,118  INFO DriverManagerConnectionProvider:45 - autocommit mode: false
     [java] 14:29:36,140  INFO DriverManagerConnectionProvider:80 - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/hibernate_tutorial
     [java] 14:29:36,161  INFO DriverManagerConnectionProvider:86 - connection properties: {user=root, password=****}
     [java] 14:29:36,298  INFO SettingsFactory:89 - RDBMS: MySQL, version: 5.0.51a
     [java] 14:29:36,301  INFO SettingsFactory:90 - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.12 ( $Date: 2005-11-17 15:53:48 +0100 (Thu, 17 Nov 2005) $, $Revision$ )
     [java] 14:29:36,351  INFO Dialect:152 - Using dialect: org.hibernate.dialect.MySQLDialect
     [java] 14:29:36,374  INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
     [java] 14:29:36,397  INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
     [java] 14:29:36,400  INFO SettingsFactory:143 - Automatic flush during beforeCompletion(): disabled
     [java] 14:29:36,402  INFO SettingsFactory:147 - Automatic session close at end of transaction: disabled
     [java] 14:29:36,404  INFO SettingsFactory:154 - JDBC batch size: 15
     [java] 14:29:36,417  INFO SettingsFactory:157 - JDBC batch updates for versioned data: disabled
     [java] 14:29:36,421  INFO SettingsFactory:162 - Scrollable result sets: enabled
     [java] 14:29:36,424  INFO SettingsFactory:170 - JDBC3 getGeneratedKeys(): enabled
     [java] 14:29:36,428  INFO SettingsFactory:178 - Connection release mode: auto
     [java] 14:29:36,440  INFO SettingsFactory:202 - Maximum outer join fetch depth: 2
     [java] 14:29:36,443  INFO SettingsFactory:205 - Default batch fetch size: 1
     [java] 14:29:36,448  INFO SettingsFactory:209 - Generate SQL with comments: disabled
     [java] 14:29:36,455  INFO SettingsFactory:213 - Order SQL updates by primary key: disabled
     [java] 14:29:36,457  INFO SettingsFactory:217 - Order SQL inserts for batching: disabled
     [java] 14:29:36,466  INFO SettingsFactory:386 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
     [java] 14:29:36,543  INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTranslatorFactory
     [java] 14:29:36,553  INFO SettingsFactory:225 - Query language substitutions: {}
     [java] 14:29:36,563  INFO SettingsFactory:230 - JPA-QL strict compliance: disabled
     [java] 14:29:36,566  INFO SettingsFactory:235 - Second-level cache: enabled
     [java] 14:29:36,568  INFO SettingsFactory:239 - Query cache: disabled
     [java] 14:29:36,570  INFO SettingsFactory:373 - Cache provider: org.hibernate.cache.NoCacheProvider
     [java] 14:29:36,573  INFO SettingsFactory:254 - Optimize cache for minimal puts: disabled
     [java] 14:29:36,582  INFO SettingsFactory:263 - Structured second-level cache entries: disabled
     [java] 14:29:36,598  INFO SettingsFactory:283 - Echoing all SQL to stdout
     [java] 14:29:36,609  INFO SettingsFactory:290 - Statistics: disabled
     [java] 14:29:36,611  INFO SettingsFactory:294 - Deleted entity synthetic identifier rollback: disabled
     [java] 14:29:36,615  INFO SettingsFactory:309 - Default entity-mode: pojo
     [java] 14:29:36,619  INFO SettingsFactory:313 - Named query checking : enabled
     [java] 14:29:36,719  INFO SessionFactoryImpl:161 - building session factory
     [java] Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: net.sf.cglib.core.DebuggingClassWriter$1
     [java] Exception in thread "main" java.lang.ExceptionInInitializerError
     [java]    at util.HibernateUtil.<clinit>(Unknown Source)
     [java]    at java.lang.Class.initializeClass(libgcj.so.9)
     [java]    at events.EventManager.createAndStoreEvent(Unknown Source)
     [java]    at events.EventManager.main(Unknown Source)
     [java] Caused by: java.lang.NoClassDefFoundError: net.sf.cglib.core.DebuggingClassWriter$1
     [java]    at java.lang.Class.initializeClass(libgcj.so.9)
     [java]    at net.sf.cglib.core.DebuggingClassWriter.toByteArray(DebuggingClassWriter.java:73)
     [java]    at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:26)
     [java]    at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
     [java]    at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145)
     [java]    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:117)
     [java]    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
     [java]    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
     [java]    at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)
     [java]    at java.lang.Class.initializeClass(libgcj.so.9)
     [java]    at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:117)
     [java]    at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:43)
     [java]    at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:162)
     [java]    at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:135)
     [java]    at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
     [java]    at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56)
     [java]    at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:302)
     [java]    at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
     [java]    at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
     [java]    at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
     [java]    at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
     [java]    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)
     [java]    at util.HibernateUtil.<clinit>(Unknown Source)
     [java]    ...3 more
     [java] Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.util.TraceClassVisitor not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:/home/erturne/Documents/hibernate_tutorial/lib/ant-1.6.5.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/ant-antlr-1.6.5.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/ant-junit-1.6.5.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/ant-launcher-1.6.5.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/ant-swing-1.6.5.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/antlr-2.7.6.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/asm-attrs.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/asm.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/c3p0-0.9.1.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/cglib-2.1.3.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/checkstyle-all.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/cleanimports.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/commons-collections-2.1.1.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/commons-logging-1.0.4.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/concurrent-1.3.2.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/dom4j-1.6.1.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/ehcache-1.2.3.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/hibernate3.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/jaas.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/jacc-1_0-fr.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/javassist.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/jaxen-1.1-beta-7.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/jboss-cache.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/jboss-common.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/jboss-jmx.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/jboss-system.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/jgroups-2.2.8.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/jta.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/junit-3.8.1.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/log4j-1.2.11.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/mysql-connector-java.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/oscache-2.1.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/proxool-0.8.3.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/swarmcache-1.0rc2.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/syndiag2.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/versioncheck.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/xerces-2.6.2.jar,file:/home/erturne/Documents/hibernate_tutorial/lib/xml-apis.jar,file:/home/erturne/Documents/hibernate_tutorial/bin/], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
     [java]    at java.net.URLClassLoader.findClass(libgcj.so.9)
     [java]    at java.lang.ClassLoader.loadClass(libgcj.so.9)
     [java]    at java.lang.ClassLoader.loadClass(libgcj.so.9)
     [java]    at java.lang.Class.forName(libgcj.so.9)
     [java]    at java.lang.Class.initializeClass(libgcj.so.9)
     [java]    ...25 more
     [java] Java Result: 1


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 29, 2008 5:56 pm 
Newbie

Joined: Sat Jun 28, 2008 2:09 pm
Posts: 2
Well, the problem has something to do with my ant build.xml file or how I'm using ant to run it. I'm able to successfully run by explicitly setting my CLASSPATH, then executing the EventManager class:
Code:
$ export CLASSPATH=/home/erturne/Documents/hibernate_tutorial/lib/antlr-2.7.6.jar:/home/erturne/...
$ cd /home/erturne/Documents/hibernate_tutorial/bin
$ java events.EventManager store


So, what's wrong with my build.xml or how I'm running using ant?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 10:36 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Make sure all of the required JAR files are on the classpath of the classloader that calls them, which is either ANT or perhaps the code that inovkes the call that creates the Hibernate Configuration or AnnotationConfiguration objects. Sometimes just putting your jar files in the lib directory isn't enough.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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.