aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate JPA - java.lang.NoClassDefFoundError: javax/persistence/Persistence Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate JPA - java.lang.NoClassDefFoundError: javax/persistence/Persistence" Watch "Hibernate JPA - java.lang.NoClassDefFoundError: javax/persistence/Persistence" New topic
Author

Hibernate JPA - java.lang.NoClassDefFoundError: javax/persistence/Persistence

Saravanan Vijayappan
Ranch Hand

Joined: Jan 02, 2007
Posts: 47
Hi, this is my first application in Hibernate JPA, I created 2 projects in eclipse 1) daks - it's a tomcat based web application 2) jpatest - JPA project in hibernate plate form. Then, I included jpatest project into my web project java module dependency path. I included all the below hibernate jars into jpa project- jpatest classpath.



Please look at my project hierarchy below



EMFactoryListener is invoked when application starts, its been configured in web.xml




EMFactory is invoked by EMFactoryListener when application starts.




JPA hibernate persistence.xml is below which presents in META-INF folder


<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" 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/persistence_1_0.xsd">
<persistence-unit name="jpatest" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.daks.domain.Environment</class>
<class>com.daks.domain.EnvironmentProperties</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost/daksdb"/>
<property name="hibernate.default_schema" value="daksdb"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="password"/>
</properties>
</persistence-unit>
</persistence>





Getting the below exception in tomcat console when the web application is deployed



I have included the required libraries in class path and included persistence.xml into META-INF/ folder. I could not find out why I am thrown the above exception, could anyone advise me please. Thanks


Cheers,<br />Sarav
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

javax.persistence.Persistence is a class in the JDK. Which version of Java do you run your application with?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Saravanan Vijayappan
Ranch Hand

Joined: Jan 02, 2007
Posts: 47
I'm using JDK6
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3825

Are you aware that Tomcat is a Servlet/JSP container, it does not implement JPA. In order to run small JPA applications you need some more work with Tomcat. Are you using EclipseLink or something, to do this?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3825

Paul Sturrock wrote:javax.persistence.Persistence is a class in the JDK. Which version of Java do you run your application with?

I think you mean JEE 5?
Saravanan Vijayappan
Ranch Hand

Joined: Jan 02, 2007
Posts: 47
I have configured Hibernate JPA entity manager in jpa project class path, i have pasted the screen shot of hibernate libraries above. I'm using jdk 1.6, please see the screen shots below. Please advise me. Thanks

Saravanan Vijayappan
Ranch Hand

Joined: Jan 02, 2007
Posts: 47
Thanks for advising me, I found what was missing. I thought, web application will be able to refer all JPA project module libraries by including JPA project as java/J2ee module into web application class path in eclipse, but that seems to be wrong. After including, JPA modules's all dependencies hibernate libs also into web application classpath solved my error. The below are my finalized HibernateJPA Mysql libs I have placed into JPA module and web application class path as well.

Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Vijitha Kumara wrote:
Paul Sturrock wrote:javax.persistence.Persistence is a class in the JDK. Which version of Java do you run your application with?

I think you mean JEE 5?


Yes, indeed I did
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate JPA - java.lang.NoClassDefFoundError: javax/persistence/Persistence