8

I am new to JPA. As per my understanding JPA itself cannot do persistence. It will need JPA Provider for persisting data into database.

JPA Provider : It is the vendor product that contains the JPA flavor (javax.persistence). For example Eclipselink, Toplink, Hibernate, etc. http://www.tutorialspoint.com/jpa/jpa_orm_components.htm

So any application which wants to use JPA for persistence it will have to use a Provider like Eclipselink, Toplink, Hibernate, etc. also. Is this correct?

Enosh Bansode
  • 1,748
  • 3
  • 18
  • 32
  • 5
    Did you have a question? – Kayaman Dec 11 '14 at 10:27
  • 3
    The question is in the title. What is a "JPA provider"? Nothing, because the correct Google search term is a "JPA persistence provider". and the answer is already in the question :/ EclipseLink, Hibernate, etc. Really weird. – Gimby Dec 11 '14 at 10:28
  • Look down the bottom of https://en.wikipedia.org/wiki/Java_Persistence_API for JPA implementations available. Any internet search would answer your "question" – Neil Stockton Dec 11 '14 at 14:28
  • If JPA specification is the bible, then JPA provider is a priest. – wypieprz Dec 11 '14 at 16:10
  • @wypieprz Maybe more as 'if the JPA spec is the blueprints, the JPA provider is the house'... – jpangamarca Mar 08 '17 at 16:35

2 Answers2

9

To provide further explanations, JPA is an API specified in the frame of the JCP as an answer to a request (e.g JSR 338 for JPA 2.1).

Several implementations of that specification exist, the main are:

In the frame of the Java platform, when a standard API is implemented, this is specified via a system called SPI (for Service Provider Interfaces). Each "vendor" of an implementation of an API has to provide a specific component which is a single interface as a starting point for the implementing classes. This is the origin of the provider word.

The Java tutorial includes an example for the sound API. An implementing class has to be mentioned in a file available to the ClassLoader after the name META-INF/services/{{MyFullInterfaceName}}.

For the JPA API, this starting point is the PersistenceProvider interface (note the spi section in the package name). Each implementation includes the declaration of the implementing class, for exemple in the eclipselink.jar you can find a file META-INF/services/javax.persistence.spi.PersistenceProvider (named after the full interface name) which contains only the full name of the provider implementation class, in the case of EclipseLink:

org.eclipse.persistence.jpa.PersistenceProvider

Most of time the application client of the API does not have to care about that declaration because it is included in the implementation JAR. The only case in which an application has to use that kind of file is when multiple implementations have to be used, for example with EclipseLink and Hibernate:

org.eclipse.persistence.jpa.PersistenceProvider
org.hibernate.ejb.HibernatePersistence

You find the implementing class also specified in the persistence.xml file (<provider/> tag).

Sometime, the JPA provider expression is used to refer to the "vendor" (EclipseLink, Hibernate, etc.) and not to the software component. Both can be considered as valid, depending on the context.

bdulac
  • 1,686
  • 17
  • 26
6

You got it right, JPA is a specification of the persistence standard. And multiple vendors have implemented the specification, like the ones you mentioned, though note that EclipseLink is based on TopLink, and the further development effort will go primarily to EclipseLink.

While you can't use JPA without the provider, you can use the vendor implementation directly, but than you lock your self to a specific provider, and lose some benefits, e.g. portability, but also gain some, e.g. features that span beyond specification.

In fact your question, though phrased differently is already answered here What's the difference between JPA and Hibernate? with the following blog emerged from the thread http://blog-tothought.rhcloud.com//post/2

Community
  • 1
  • 1
Master Slave
  • 27,771
  • 4
  • 57
  • 55