0

I am pretty new in JPA\Hibernate and I have the following doubt.

Into the pom.xml file of a Spring MVC projet I found the following dependency that are added to my project (that use JPA to implement my repository).

<dependencies>
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <version>1.0.0.Final</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.3.11.Final</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>1.8.2.RELEASE</version>
    </dependency>

</dependencies>

So I am trying to understand the architecture of this projet and what exactly does these dependendency.

So from what I know JPA is only a specification and I can't use it without an implementation. So is JPA something like a set of interface that specify what operation I can perform and then I need something that implement that operation?

1) So, from what I have understand, the first artifact (the hibernate-jpa-2.1-api) should be the JPA specification.

Here the structure documentation: https://docs.jboss.org/hibernate/jpa/2.1/api/ and infact looking into the listed package it seems to me that are almost interfaces but not implementation classes.

If this assertion is correct my doubt is: why if it is the JPA specification it is provided under hibernate that should be an implementation o this specification? (Exist different version of the JPA spcificication or is it unique?)

2) The hibernate-core artifact should be the JPA implementation (from what I know exist various implementation and Hibernate is one of these, another one is EclipseLink and so on). So this artifact provide me the tool that allows me to interact concretely with the database)

3) The spring-data-jpa is a part of the Spring Data that make easier create JPA repository (for example allow me to use the "Specification" concept to create query)

Is it my reasoning correct or am I missing something?

AndreaNobili
  • 40,955
  • 107
  • 324
  • 596

1 Answers1

0

JPA is just annotations (kind of interfaces) you can use to mark your class Entities and relations. Later you can use Hibernate (or EclipseLink) as implementation of the JPA.

Thus you can change implementation leaving annotations (interfaces).

Check also this

Community
  • 1
  • 1
StanislavL
  • 56,971
  • 9
  • 68
  • 98