-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Not finding things in classpath?!
PostPosted: Sat Jan 20, 2007 1:54 pm 
Newbie

Joined: Sat Jan 20, 2007 10:29 am
Posts: 8
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.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 20, 2007 2:01 pm 
Newbie

Joined: Sat Jan 20, 2007 10:29 am
Posts: 8
Sorry, I forgot to mention that I have the User.class file in the following location:
Code:
WEB-INF/classes/com/vio/cms/server/User.class


I assume it is beyond doubt that WEB-INF/classes is in the classpath since it is the default location where classes reside in any Tomcat servlet.

Thank you again.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 21, 2007 12:07 am 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
The exception that you got was ExceptionInInitializer which indicates that your class(User) could have a static initializer that did not complete normally. Can you check if there is a static block in the User class and that can return normally ?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 21, 2007 5:58 am 
Newbie

Joined: Sat Jan 20, 2007 10:29 am
Posts: 8
rajasaur wrote:
The exception that you got was ExceptionInInitializer which indicates that your class(User) could have a static initializer that did not complete normally. Can you check if there is a static block in the User class and that can return normally ?

Thank you for your answer.
Following the example shown here, it is my code that actually throws ExceptionInInitializerError when catching an exception from
Code:
            sessionFactory = new Configuration().configure().buildSessionFactory();


This is my HibernateUtil:
Code:
public class HibernateUtil {

    private static final SessionFactory sessionFactory;

    static {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            sessionFactory = new Configuration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed: " + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}


In the mean time I found this thread complaining about a similar problem in a Tomcat environment and suggesting that not only asm.jar, but also jta.jar should be added to common/lib.

I didn't add jta.jar to my common/lib directory in the beginning because of this description:
Quote:
jta.jar (unknown)
- Standard JTA API
- runtime, required for standalone operation (outside application server)

I also use Tomcat, so "outside application server" is not applicable for me.
Anyway, I've now added jta.jar to common/lib after having read that thread, but the result is the same.

Any further help will be highly appreciated. Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 21, 2007 9:17 am 
Newbie

Joined: Sat Mar 05, 2005 2:36 pm
Posts: 19
rajasaur wrote:
The exception that you got was ExceptionInInitializer which indicates that your class(User) could have a static initializer that did not complete normally. Can you check if there is a static block in the User class and that can return normally ?


I am not sure about that. If you look down the stack trace, you can see that the class was not found: MappingException followed by a ClassNotFoundException.
Code:
org.hibernate.MappingException: entity class not found: com.vio.cms.server.User
...
java.lang.ClassNotFoundException: com.vio.cms.server.User


You might have not put the class in the war, at least not into the right place. According to the HBM it should be in the right package:
Code:
<hibernate-mapping package="com.vio.cms.server">
        <class name="User" table="users">
        ...


Check whether your jar file contains the compiled class, or whether you can find the class at the right location in WEB-INF/classes.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 21, 2007 10:36 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Is there anything wrong with the servlet example that you can download and read about in chapter 1 of the Hibernate documentation?

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 21, 2007 8:55 pm 
Newbie

Joined: Sat Jan 20, 2007 10:29 am
Posts: 8
kariem wrote:
You might have not put the class in the war, at least not into the right place. According to the HBM it should be in the right package:
Code:
<hibernate-mapping package="com.vio.cms.server">
        <class name="User" table="users">
        ...


Check whether your jar file contains the compiled class, or whether you can find the class at the right location in WEB-INF/classes.


I've already specified in my second message that the User.class file is in the right place, i.e. WEB-INF/classes/com/vio/cms/server. I've checked it way before thinking about opening this topic here and rechecked it right now:
Code:
$ ls -l /var/lib/tomcat5.5/webapps/cms/WEB-INF/classes/com/vio/cms/server/User.class
-rw-r--r-- 1 tomcat55 nogroup 1168 2007-01-20 17:07 /var/lib/tomcat5.5/webapps/cms/WEB-INF/classes/com/vio/cms/server/User.class

I'm still clueless about what might cause that exception. :(


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 21, 2007 9:12 pm 
Newbie

Joined: Sat Jan 20, 2007 10:29 am
Posts: 8
christian wrote:
Is there anything wrong with the servlet example that you can download and read about in chapter 1 of the Hibernate documentation?

I cannot say that, because I only used parts of that example for my servlet that uses Hibernate from a method called via RPC (hence the "Exception while dispatching incoming RPC call").

If I can't get a clue about what causes that exception I'm going to implement that servlet example described in chapter 1 step by step and I'll let you know if anything goes wrong.

Thank you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.