aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate/JSP: NoClassDefFoundError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate/JSP: NoClassDefFoundError" Watch "Hibernate/JSP: NoClassDefFoundError" New topic
Author

Hibernate/JSP: NoClassDefFoundError

Duffman Be
Greenhorn

Joined: Nov 14, 2009
Posts: 7
Hello,

I'm experiencing a problem using Hibernate featuring JSP. I created a winform application using Hibernate and now I want to make the same application using JSP so I thought I could copy the model package as well as the hibernate config-files and the Hibernate-Util class. However, when I'm trying to create the database, I keep getting the error:
"Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: javax/persistence/Entity".
I can surf to my index.jsp (because Tomcat does start) but the application wasn't able to load/create the database scheme into my hibernate. Funny thing is that the exact configuration does work in my winform application. As far as I know I'm using the exact same libraries of Hibernate. I'm using annotations. If you need to see some classes I haven't pasted in this post, please let me know.

hibernateMySQL.cfg.xml wrote:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/bioscoopholding</property>
<property name="connection.username">bioscoopholding</property>
<property name="connection.password">cocacola</property>

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

<!-- Create DB schema based on mappings
<property name="hbm2ddl.auto">create</property> -->





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

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

<!-- Reference to all the mapping files used -->
<!--<mapping resource="persistence/Artist.hbm.xml"/>-->
<mapping class="model.Zaal" />
<mapping class="model.Complex" />
<mapping class="model.Holding" />
<mapping class="model.Zetel" />
<mapping class="model.Zone" />
<mapping class="model.Ticket" />
<mapping class="model.Voorstelling" />
<mapping class="model.Beheerder" />
<mapping class="model.Bestelling" />
<mapping class="model.Verkooppunt" />
<mapping class="model.Klant" />
<mapping class="model.Waardering" />
<mapping class="model.Film" />
<mapping class="model.Filmmaatschappij" />
<mapping class="model.Genre" />
<mapping class="model.Acteursrol" />
<mapping class="model.Acteur" />
<mapping class="model.MedewerkersFunctie" />
<mapping class="model.Medewerker" />
<mapping class="model.Onderscheiding" />
</session-factory>
</hibernate-configuration>


HibernateUtil.java wrote:
package persistence;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateUtil {
private static final SessionFactory sessionFactory;

static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new
AnnotationConfiguration().configure("hibernateMySQL.cfg.xml").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;
}
}


Listenerclass that instantiates my model wrote:
package listeners;

import org.hibernate.Session;
import org.hibernate.Transaction;

import javax.servlet.ServletContextListener;
import javax.servlet.ServletContextEvent;

import persistence.HibernateUtil;

/**
* Created by IntelliJ IDEA.
* User: Simon
* Date: 14-nov-2009
* Time: 13:02:17
* To change this template use File | Settings | File Templates.
*/
public class initialiseerModelListener implements ServletContextListener{
public void contextInitialized(ServletContextEvent servletContextEvent) {
Session session;
Transaction tx;
session = HibernateUtil.getSessionFactory().getCurrentSession();
tx = session.beginTransaction();//never reaches this line since I can't get my session.
}

public void contextDestroyed(ServletContextEvent servletContextEvent) {

}
}


Does somebody know what I'm doing wrong? I'm assuming the problem can't be found in one of my model classes because the model-classes do work in my winform application.



Thank you,
Duffman
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

Does your JPA API library is in your classpath?


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
Duffman Be
Greenhorn

Joined: Nov 14, 2009
Posts: 7
I don't think so. Is there a special library required for web-applications?

Anyway, you can see my directory structure here:
http://users.telenet.be/duffman/dirStruct.jpg

I'm away from my keyboard for 3 hours or so but thanks for your quick reaction!

Greetings,
Duffman
Duffman Be
Greenhorn

Joined: Nov 14, 2009
Posts: 7
//update:

I wrote a small project reproducing the error. Can someone please look into it and tell me what I'm doing wrong. I did not rar the libraries because of the file size but you can see which libraries I use in my first post.

Link to project: http://users.telenet.be/duffman/TestProject.rar
(only src and web directory)

Thank you!
Duffman-

EDIT: I managed to fix the error. I added the library "ejb3-persistence.jar" to my classpath, and everything is working fine (for now. )
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate/JSP: NoClassDefFoundError