• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
javax.persistence.Persistence is a class in the JDK. Which version of Java do you run your application with?
 
Saravanan Vijayappan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using JDK6
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Vijitha Kumara
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Don't mess with me you fool! I'm cooking with gas! Here, read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic