Hi,
I'm quite a newbie with Hibernate, so please be patient with me.
I have a basic servlet that uses Hibernate 3.2 and that I'm trying to get running under Tomcat 5.5.
The first weird issue:
Code:
DEBUG http-8180-Processor25 org.hibernate.util.DTDEntityResolver - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-configuration-3.0.
dtd]
DEBUG http-8180-Processor25 org.hibernate.util.DTDEntityResolver - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
DEBUG http-8180-Processor25 org.hibernate.util.DTDEntityResolver - unable to locate [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd] on cla
sspath
I can see that Hibernate gets the DTD file from the web instead of getting it from hibernate3.jar, as expected after having read the docs. And yes, hibernate3.jar
does exist:
Code:
$ ls -l /usr/share/tomcat5.5/common/lib/hibernate3.jar
-rw-r--r-- 1 root root 2198080 2006-11-16 16:32 /usr/share/tomcat5.5/common/lib/hibernate3.jar
and /usr/share/tomcat5.5/common/lib is in the classpath, as seen earlier in the log (I hope I'm looking in the right place to see the current classpath used for this servlet):
Code:
org.apache.catalina.loader.StandardClassLoader@1d49247
DEBUG main org.apache.jasper.compiler.JspRuntimeContext - Compilation classpath initialized: /var/lib/tomcat5.5/webapps/cms/WEB-INF/classes/:/var/lib/tomcat5
.5/webapps/cms/WEB-INF/lib/log4j-1.2.11.jar:/var/lib/tomcat5.5/work/Catalina/localhost/cms:/var/lib/tomcat5.5/webapps/cms/WEB-INF/classes/:/var/lib/tomcat5.5/
webapps/cms/WEB-INF/lib/log4j-1.2.11.jar:/var/lib/tomcat5.5/shared/classes/:/usr/share/tomcat5.5/common/classes/:/usr/share/tomcat5.5/common/i18n/tomcat-i18n-
es.jar:/usr/share/tomcat5.5/common/i18n/tomcat-i18n-fr.jar:/usr/share/tomcat5.5/common/i18n/tomcat-i18n-en.jar:/usr/share/tomcat5.5/common/i18n/tomcat-i18n-ja
.jar:/usr/share/java/xercesImpl.jar:/usr/share/tomcat5.5/common/lib/naming-resources.jar:/usr/share/tomcat5.5/common/lib/jasper-compiler.jar:/usr/share/tomcat
5.5/common/lib/naming-factory.jar:/usr/share/tomcat5.5/common/lib/jasper-runtime.jar:/usr/share/java/commons-collections3-3.1.jar:/usr/share/java/ecj.jar:/usr
/share/java/commons-dbcp-1.2.1.jar:/usr/share/java/commons-el-1.0.jar:/usr/share/java/jsp-api-2.0.jar:/usr/share/java/commons-pool-1.3.jar:/usr/share/java/ser
vlet-api-2.4.jar:/usr/share/tomcat5.5/common/lib/mysql-connector-java-5.0.4-bin.jar:/usr/share/tomcat5.5/common/lib/gwt-servlet.jar:/usr/share/tomcat5.5/commo
n/lib/hibernate3.jar:/usr/share/tomcat5.5/common/lib/commons-logging-1.0.4.jar:/usr/share/tomcat5.5/common/lib/asm-attrs.jar:/usr/share/tomcat5.5/common/lib/l
og4j-1.2.11.jar:/usr/share/tomcat5.5/common/lib/dom4j-1.6.1.jar:/usr/share/tomcat5.5/common/lib/antlr-2.7.6.jar:/usr/share/tomcat5.5/common/lib/cglib-2.1.3.ja
r:/usr/share/tomcat5.5/common/lib/asm.jar:/usr/share/tomcat5.5/common/lib/commons-collections-2.1.1.jar:/var/lib/tomcat5.5/webapps/:/usr/lib/j2sdk1.5-sun/jre/
lib/jcert.jar:/usr/lib/j2sdk1.5-sun/jre/lib/jnet.jar:/usr/lib/j2sdk1.5-sun/jre/lib/jsse.jar:/usr/share/tomcat5.5/bin/bootstrap.jar:/usr/share/java/commons-log
ging-api-1.0.4.jar:/usr/lib/j2sdk1.5-sun/jre/lib/ext/sunjce_provider.jar:/usr/lib/j2sdk1.5-sun/jre/lib/ext/sunpkcs11.jar:/usr/lib/j2sdk1.5-sun/jre/lib/ext/dns
ns.jar:/usr/lib/j2sdk1.5-sun/jre/lib/ext/localedata.jar
The second weird issue seems to be classpath related, too: I get the following exception when parsing the mapping configuration file User.hbm.xml:
Code:
org.hibernate.MappingException: entity class not found: com.vio.cms.server.User
This is my hibernate.cfg.xml:
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.datasource">java:comp/env/jdbc/MySQLDB</property>
<property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">true</property>
<!--<property name="hbm2ddl.auto">create</property>-->
<mapping resource="com/vio/cms/server/User.hbm.xml" />
</session-factory>
</hibernate-configuration>
And this is my mapping configuration file User.hbm.xml:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.vio.cms.server">
<class name="User" table="users">
<id name="id" type="long" column="id">
<generator class="native"/>
</id>
<property name="username" type="string"/>
<property name="first_name" type="string"/>
<property name="last_name" type="string"/>
</class>
</hibernate-mapping>
The following sequence appears in the log earlier than the above mentioned MappingException and here it looks like the class com.vio.cms.server.User is being located successfully:
Code:
DEBUG http-8180-Processor25 org.apache.catalina.loader.WebappClassLoader - loadClass(com.vio.cms.server.User, false)
DEBUG http-8180-Processor25 org.apache.catalina.loader.WebappClassLoader - loadClass(com.vio.cms.server.User, false)
DEBUG http-8180-Processor25 org.apache.catalina.loader.WebappClassLoader - Searching local repositories
DEBUG http-8180-Processor25 org.apache.catalina.loader.WebappClassLoader - Searching local repositories
DEBUG http-8180-Processor25 org.apache.catalina.loader.WebappClassLoader - findClass(com.vio.cms.server.User)
DEBUG http-8180-Processor25 org.apache.catalina.loader.WebappClassLoader - findClass(com.vio.cms.server.User)
DEBUG http-8180-Processor25 org.apache.catalina.loader.WebappClassLoader - securityManager.checkPackageDefinition
DEBUG http-8180-Processor25 org.apache.catalina.loader.WebappClassLoader - securityManager.checkPackageDefinition
DEBUG http-8180-Processor25 org.apache.catalina.loader.WebappClassLoader - findClassInternal(com.vio.cms.server.User)
DEBUG http-8180-Processor25 org.apache.catalina.loader.WebappClassLoader - findClassInternal(com.vio.cms.server.User)
DEBUG http-8180-Processor25 org.apache.catalina.loader.WebappClassLoader - Returning class class com.vio.cms.server.User
DEBUG http-8180-Processor25 org.apache.catalina.loader.WebappClassLoader - Returning class class com.vio.cms.server.User
And here is the full stack trace I can see in the log when getting that MappingException (entity class not found):
Code:
ERROR http-8180-Processor25 org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/cms] - Exception while dispatching incoming RPC call
java.lang.ExceptionInInitializerError
at com.vio.cms.server.HibernateUtil.<clinit>(HibernateUtil.java:25)
at com.vio.cms.server.CmsServiceImpl.getUsernames(CmsServiceImpl.java:38)
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:585)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:262)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServiceServlet.java:146)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
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:585)
at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:243)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:275)
at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:161)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:245)
at org.apache.catalina.core.ApplicationFilterChain.access$0(ApplicationFilterChain.java:177)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:156)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:152)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
Caused by: org.hibernate.MappingException: entity class not found: com.vio.cms.server.User
at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:99)
at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:168)
at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:44)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:118)
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 com.vio.cms.server.HibernateUtil.<clinit>(HibernateUtil.java:21)
... 35 more
Caused by: java.lang.ClassNotFoundException: com.vio.cms.server.User
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:96)
... 44 more
I'm not even sure about whether it's a Hibernate or a Tomcat related issue. Maybe the answer is obvious, but not for me.
I apologize for the lengthy post (I just wanted to provide as much useful data as possible). Please ask me for any further relevant information, if needed.
Thank you in advance.