-->
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.  [ 7 posts ] 
Author Message
 Post subject: org.hibernate.InvalidMappingException: Could not parse mappi
PostPosted: Tue Mar 11, 2008 9:05 pm 
Newbie

Joined: Mon Jan 28, 2008 1:55 pm
Posts: 19
Hibernate version:
3.0
hibernate.cfg.xml:
Code:
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
   
        <!-- Settings for a local HSQL (testing) database. -->
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/dbname</property>
        <property name="connection.username">root</property>
        <property name="connection.password">password</property>

        <!-- Use the C3P0 connection pool. -->
        <property name="c3p0.min_size">3</property>
        <property name="c3p0.max_size">5</property>
        <property name="c3p0.timeout">1800</property>
   
        <!-- Disable second-level cache. -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        <property name="cache.use_query_cache">false</property>
        <property name="cache.use_minimal_puts">false</property>
        <property name="max_fetch_depth">3</property>
   
        <!-- Print SQL to stdout. -->
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>
   
        <!-- Drop and then re-create schema on SessionFactory build, for testing. -->
        <property name="hbm2ddl.auto">create</property>
   
        <!-- Bind the getCurrentSession() method to the thread. -->
        <property name="current_session_context_class">thread</property>

        <!-- Hibernate XML mapping files -->
        <mapping resource="test/TestDAO.hbm.xml"/>
    </session-factory>

</hibernate-configuration>

TestDAO.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>
   <class name="TestDAO" table="TST_TestDAO">
      <id name="id" column="testDAOID" type="long">
         <generator class="native" />
      </id>
      <property name="testParam" type="integer" />
   </class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
TestServlet
Code:
public class TestServlet extends HttpServlet{
   private static final long serialVersionUID = -4475599757796846392L;

   public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      Session session = HibernateUtil.getSessionFactory().getCurrentSession();
      session.beginTransaction();
      TestDAO testDAO = new TestDAO();
      testDAO.setTestParam(5);
      session.save(testDAO);
      session.close();
      
   }
}

TestDAO.java
Code:
package test;

public class TestDAO {
   
   private Long id = null;
   
   private int testParam;
   
   public TestDAO(){
      
   }

   public Long getId() {
      return id;
   }

   public void setId(Long id) {
      this.id = id;
   }

   public int getTestParam() {
      return testParam;
   }

   public void setTestParam(int testParam) {
      this.testParam = testParam;
   }

}

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;
    }
}

Full stack trace of any exception that occurs:
Code:
exception

javax.servlet.ServletException: Servlet execution threw an exception

root cause

java.lang.ExceptionInInitializerError
   business_logic.HibernateUtil.<clinit>(HibernateUtil.java:17)
   business_logic.servlets.login.Login.processRequest(Login.java:42)
   business_logic.servlets.BaseServlet.doPost(BaseServlet.java:42)
   business_logic.servlets.BaseServlet.doGet(BaseServlet.java:25)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

root cause

org.hibernate.MappingException: entity class not found: TestDAO
   org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:99)
   org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:168)
   org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:44)
   org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:124)
   org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
   org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
   org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
   org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
   org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)
   business_logic.HibernateUtil.<clinit>(HibernateUtil.java:13)
   business_logic.servlets.login.Login.processRequest(Login.java:42)
   business_logic.servlets.BaseServlet.doPost(BaseServlet.java:42)
   business_logic.servlets.BaseServlet.doGet(BaseServlet.java:25)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

root cause

java.lang.ClassNotFoundException: TestDAO
   org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1360)
   org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1206)
   java.lang.ClassLoader.loadClassInternal(Unknown Source)
   java.lang.Class.forName0(Native Method)
   java.lang.Class.forName(Unknown Source)
   org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
   org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:96)
   org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:168)
   org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:44)
   org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:124)
   org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
   org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
   org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
   org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
   org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)
   business_logic.HibernateUtil.<clinit>(HibernateUtil.java:13)
   business_logic.servlets.login.Login.processRequest(Login.java:42)
   business_logic.servlets.BaseServlet.doPost(BaseServlet.java:42)
   business_logic.servlets.BaseServlet.doGet(BaseServlet.java:25)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

Name and version of the database you are using:
MySQL 5.0


This exception is thrown in my HibernateUtil class when I try to create the SessionFactory object in the static block. I am able to run hbm2ddl to generate my database schema so I'm not sure why Hibernate can't find TestDAO when I try to get the SessionFactory. Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 12, 2008 5:08 pm 
Newbie

Joined: Mon Jan 28, 2008 1:55 pm
Posts: 19
Any suggestions?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 12, 2008 5:17 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
EdLaFave wrote:
Any suggestions?


This is a ClassNotFoundException and that means the TestDAO class is not in class path. Are you sure this class is copied with the web app?


Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 12, 2008 6:23 pm 
Newbie

Joined: Mon Jan 28, 2008 1:55 pm
Posts: 19
I'm 100% positive TestDAO made its way into the Tomcat 6.0/webappname/WEB-INF/classes directory, thats why this error is so strange. Is there some file I have to specify the location of TestDAO? Do I have to enter anything in the web.xml file?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 12, 2008 6:27 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
EdLaFave wrote:
I'm 100% positive TestDAO made its way into the Tomcat 6.0/webappname/WEB-INF/classes directory, thats why this error is so strange. Is there some file I have to specify the location of TestDAO? Do I have to enter anything in the web.xml file?


how about:

Code:
<class name="test.TestDAO" table="TST_TestDAO">




Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 12, 2008 7:04 pm 
Newbie

Joined: Mon Jan 28, 2008 1:55 pm
Posts: 19
That was it, thank you very much!!!!!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 12, 2008 7:06 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
EdLaFave wrote:
That was it, thank you very much!!!!!



Sorry I didn't see it the first time. I need to go and check my eyesight :)



Farzad-


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