Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Standalone JPA example

 
subir rastogi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,
I am trying to create a simple JPA example using Java SE 5, Hibernate and MySQL.
I have created a persistence.xml and entity classes but when I run the example, I got the error-


Persistence.xml


Please let me know what is wrong with persistence.xml.

Thanks.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you put the persistence.xml file in your META-INF directory ? Is this directory in your CLASSPATH ?
 
subir rastogi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, persistence.xml is in the classpath.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is META-INF in the classpath ?
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't played with standalone JPA much, but shouldn't that persistence.xml have an persistence-provider element which points to the Hibernate persistence provider class? Also posting the entire exception stacktrace might also help.
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jaikiran Pai wrote:I haven't played with standalone JPA much, but shouldn't that persistence.xml have an persistence-provider element which points to the Hibernate persistence provider class?

Indeed, but if memory serves it's called "<provider>", not "persistence-provider" (unless things have changed since JPA 1.0). You'll also need "<class>" elements for all the classes that should be managed by JPA.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lester Burnham wrote:
but if memory serves it's called "<provider>", not "persistence-provider"

Indeed (even in JPA2).
 
subir rastogi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have to add provider class, in case of hibernate, how to find which is the jpa provider class?

thanks
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Hibernate documentation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic