I have lately been trying to use Hibernate to develop a web application for Tomcat, which I have successfully written and tested using Eclipse's web tools. When I publish the web application with Eclipse, it works fine. But when I put the .war file in Tomcat's web-apps directory and start it normally, it gives me the following error:
INFO: Deploying web application archive
webappname.war
Starting the Hibernate listener
Initial SessionFactory creation failed.
java.lang.NoClassDefFoundError: net.sf.cglib.core.DebuggingClassWriter$1
java.lang.NoClassDefFoundError: net.sf.cglib.core.DebuggingClassWriter$1
at java.lang.Class.initializeClass(libgcj.so.7rh)
at net.sf.cglib.core.DebuggingClassWriter.toByteArray(DebuggingClassWriter.java:73)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:26)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:117)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)
at java.lang.Class.initializeClass(libgcj.so.7rh)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:107)
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:269)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:425)
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:1291)
at
mypackage.HibernateUtil.<clinit>(HibernateUtil.java:17)
at java.lang.Class.initializeClass(libgcj.so.7rh)
at
mypackage.HibernateListener.contextInitialized(HibernateListener.java:19)
The stack trace is quite long, but unfortunately there is no pertinent error information after that.
The problem seems to be that the Hibernate listener, which runs when the web application is instantiated and is intended to create a SessionFactory for Hibernate, fails. The code for getting the SessionFactory is from HibernateUtil, from
http://www.hibernate.org/42.html#A11 and the configuration file is based on the one found in
http://www.hibernate.org/114.html.
At first glance, I thought this problem was merely that one of Hibernate's third-party jars was missing from WEB-INF/lib, but I checked, and hibernate3.jar, the JDBC driver, and all the third-party JARs were in the directory, including cglib.
Is there any kind of security feature on Tomcat that makes this not work? What is so strange to me is that when I published it using Eclipse's web tools, it worked fine. Only when I tried using a WAR did this become a problem.
Any help would be very much appreciated.