-->
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.  [ 3 posts ] 
Author Message
 Post subject: Starting up a standalone Hibernate EntityManager application
PostPosted: Tue Aug 14, 2007 4:00 pm 
Newbie

Joined: Thu Jul 26, 2007 2:28 pm
Posts: 9
I kept having problem running my first Hibernate Entity Manager standalone application (build with Java SE 1.6) adapted from the original tutorial HelloWorld.java which I had success in running with the Hibernate Core 3.2. It always complained about the missing class org.hibernate.MappingException even after I included all of the jar files in distributed libraries. I tried to create the build.xml to copy the persistence.xml to the bin/META-INF but the problem persisted.

Here is the exception stack trace:

Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/MappingException
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:119)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
at hello.HelloWorld.main(HelloWorld.java:19)


Hibernate version:

Hibernate Entity Manager 3.3.1GA

Mapping documents:

My persistence.xml:

<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation='http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/ ... ce_1_0.xsd version="1.0"'>
<persistence-unit name="manager" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="hibernate.ejb.cfgfile"
value="/hibernate.cfg.xml"></property>
<property name="hibernate.archive.autodetection" value="class" />
</properties>
</persistence-unit></persistence>

My hibernate.cfg.xml:


<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- Use the C3P0 connection pool provider -->
<property name="c3p0.min_size">5</property>
<property name="c3p0.max_size">20</property>
<property name="c3p0.timeout">300</property>
<property name="c3p0.max_statements">50</property>
<property name="c3p0.idle_test_period">3000</property>

<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<!-- Print formated SQL -->
<property name="format_sql">true</property>

<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>

<!--<mapping resource="hello/Message.hbm.xml"/>-->

</session-factory>

</hibernate-configuration>

Code between sessionFactory.openSession() and session.close():

// The exception occurred on this very first line.
EntityManagerFactory emf = Persistence.createEntityManagerFactory("manager");
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();

Message message = new Message("Hello World");
em.persist(message);

tx.commit();
em.close();

EntityManager em2 = emf.createEntityManager();
EntityTransaction tx2 = em2.getTransaction();
tx2.begin();

List messages = em2.createQuery("select m from Message m order by m.text asc")
.getResultList();
System.out.println(messages.size() + " mesage(s) found: ");
for (Object m : messages)
{
Message loadedMsg = (Message) m;
System.out.println(loadedMsg.getText());
}

tx2.commit();
em2.close();


Full stack trace of any exception that occurs:

Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/MappingException
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:119)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
at hello.HelloWorld.main(HelloWorld.java:19)



Name and version of the database you are using:

MySQL connector 3.1.13 and MySQL Server 4.1


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 14, 2007 5:09 pm 
Newbie

Joined: Thu Jul 26, 2007 2:28 pm
Posts: 9
After some searches, I found out that the MappingException class is located inside the hibernate3.jar which I thought already in the hibernate-entityManager.jar file.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 14, 2007 7:24 pm 
Newbie

Joined: Thu Jul 26, 2007 2:28 pm
Posts: 9
It turned out that I had to add back all of the required jar files as distributed in Hibernate Core 3.2. Ant builder seemed to have a problem. It couldn't find my .properties and .xml files in the root directory to copy over to the build directory.


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