• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate/JSP: NoClassDefFoundError  RSS feed

Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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"
<!-- 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" />

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
} 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,
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does your JPA API library is in your classpath?
Duffman Be
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think so. Is there a special library required for web-applications?

Anyway, you can see my directory structure here:

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

Duffman Be
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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!

EDIT: I managed to fix the error. I added the library "ejb3-persistence.jar" to my classpath, and everything is working fine (for now. )
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!