简体   繁体   中英

If JPA is really only a specification, then how can we do?

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???

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM