Win a copy of Android Programming: The Big Nerd Ranch Guide this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB3 JPA implementation  RSS feed

Tejas Jain
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got an ejb3-persistence.jar (52KB) from Hibernate site.
If I only want to use JPA specific API to create a DB access layer, is this jar enough? Do I have to use it with other hibernate jar files?

Is JPA a complete and self-sufficient API (like EJB2.x API) to access DB?
Gregg Bolinger
Ranch Hand
Posts: 15304
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To use JPA you'll need an API that implements it, like Hibernate. To use JPA with Hibernate you'll need the following JAR files (I could be off by one or 2)

hibernate-annotations (if using annotations)
hibernate-commons-annotations (if using annotations)

Yea, I think that's all.
[ April 23, 2008: Message edited by: Gregg Bolinger ]
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like you're going to be using Hibernate with that ejb3-persistence.jar file of yours.

Gregg is correct, if you want to use JPA, you need a framework that supports it. Here's what you need to support a basic JPA & Hibernate development environment:

* A JDBC compliant Database. (and the ability to perform the most basic of database administration tasks.)
* The JDK 1.5 or better, as annotations didn't exist before Java 5
* JDBC Drivers for your Database -that's how Hibernate connects to your database of choice
* The various jar files and libraries associated with the Hibernate Core and Hibernate Annotations (essentially, you need Hibernate)
* A properly configured hibernate.cfg.xml file on your runtime classpath.

My website has a free tutorial that goes through all of the steps required to set up a JPA and Hibernate environment.

How to Set Up a Hibernate and JPA (Java Persistence API) Environment on Windows

I even go through the installation in this free youtube video.

CBT Video Tutorial on Setting Up a JPA Environment with MySQL & the JDK

Hope that all helps!

-Cameron McKenzie
[ April 23, 2008: Message edited by: Cameron Wallace McKenzie ]
John King
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ejb3-persistence.jar contains only one class (Persistence), four interfaces, several exceptions, and many annotations. It does not have much implementations, and is completely different from EJB2.x API.
Sun has the copyright for the code in ejb3-persistence.jar. JBoss put it in this jar file.

I used Hibernate alone with hibernate3.jar (with some commons jars) before.
It worked fine. We can say JPA is built on top of Hibernate (or Toplink, ...) and JPA API itself is not enough to create a DB access layer.

If your implementation is based on Hibernate EJB3 JPA, your code is not portable to other EJB3 JPA implementations (e.g., Toplink...)
[ April 23, 2008: Message edited by: John King ]
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!