Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a JPA Provider? [closed]

Tags:

java

jpa

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?

like image 387
Enosh Bansode Avatar asked Dec 11 '14 10:12

Enosh Bansode


1 Answers

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:

  • EclipseLink
  • Hibernate
  • OpenJPA
  • DataNucleus

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.

like image 181
bdulac Avatar answered Oct 04 '22 10:10

bdulac