0

In the question below EVERYBODY

What's the difference between JPA and Hibernate?

told that JPA is specification.It is something abstract without Eclipselink or Hibernate

Is JPA javax.persistence.sth right?

Moreover we can use concrete things like

javax.persistence.EntityManager.persiste javax.persistence.EntityManager.delete/remove

EDIT

Does eclipselink and hibernate put their own code into these packages, these classes???

Community
  • 1
  • 1
merveotesi
  • 2,145
  • 15
  • 53
  • 84

2 Answers2

2

JPA is a specification, and a number of implementors provide implementations that follow the specification.

So, if you use JPA as it is meant to be used, you can then choose from one or more of the implementors and it should "plug-and-play" work. In other words, you shouldn't have to change your code, because the implementation will do what the specification promises.

--- As for the difference between JPA and Hibernate ---

JPA is a specification, but Hibernate is an implementation. If you write against JPA you can change between JPA compatible implementations with some ease; but, if you write against Hibernate, to change you effectively need to rewrite your database access code.

Note that Hibernate also provides some JPA compatibility, if you take care to use only the JPA compatible part of Hibernate, you effectively are writing against JPA with Hibernate providing the implementation.

There is a receipe for doing JPA development that works quite well at preventing non-JPA (implementation specific) code from being written.

  1. Find the JPA jar for the version of JPA you are targeting.
  2. Add that jar to the compile class path, and the run time classpath.
  3. Find the JPA provider you wish to use (Hibernate, etc).
  4. Add that / those jars to the run time classpath only.
Edwin Buck
  • 69,361
  • 7
  • 100
  • 138
  • Thanks very much but hibernate has org.hibernate.session, also in some hibernate tutorials in parallel to your words entityManager is used. Then why is session for. I want to know if Hibernate entitymanager implementation is built on org.hibernate.session – merveotesi Jul 01 '14 at 14:05
  • Well, you have to pick the tutorial that fits your needs. If you are doing JPA, pick a JPA tutorial. If you are binding to Hibernate outside of JPA, a Hibernate tutorial. – Edwin Buck Jul 01 '14 at 14:09
0

JPA is Java Persistence API released as a JSR (Java Specification Requests) by JCP (Java Community Process).

It is kind of specification; in other words like interface, no implementation includes.

Every vendor (implementors) who interested this spec needs to implement as it says in specification document.

Here is example JPA 2.0 spec

Wundwin Born
  • 3,467
  • 19
  • 37