JPA versus JPA: What's the difference?

I am bit confused about the difference between Spring Data-JPA and JPA. I know about JPA that it is a specification for persisting the Java Objects to a relational database using popular ORM technology ie In other words JPA provides interfaces and other ORM technologies, implements those interfaces known as JPA provider eg Hibernate.

Now what exactly is Spring Data JPA. Is Spring Data JPA has added some more functionality (Interfaces) over JPA and still it is specified only or it is also a JPA provider?

I saw Spring Data JPA works around repositories (DAO layer: if I am not wrong). So I mean how it is different using 'Spring Data JPA + Hibernate' or only using 'Hibernate' directing?


I saw Spring, JPA works around repositories (DAO layer: if I am not wrong). So I mean how it is different using 'Spring JPA + Hibernate' or only using 'Hibernate' directly?

As you said, JPA is an specification while Hibernate is a particular implementation of that specification (these implementations are usually referred to as Providers). By using Hibernate you tie yourself to that provider restricting your freedom to switch to another option when required (for example, you want to use EclipseLink or ObjectDB instead because Hibernate has a bug that halts your development process).

Quoting Spring Data JPA's documentation:

Implementing a data access layer of an application has been cumbersome for quite a while. Too much boilerplate code had to be written. Domain classes were anemic and haven't been designed in a real object oriented or domain driven manner.

Using both of these technologies makes developers life a lot easier regarding rich domain model's persistence. Nevertheless the amount of boilerplate code to implement repositories, especially is still quite high. So the goal of the repository abstraction of Spring Data is to reduce the effort to implement data access layers for various persistence stores significantly.

To sum it up, it is on top of JPA adding another layer of abstraction, kind of defining a standard-based design to support Persistence Layer in a Spring context. Those defined interfaces (known to Spring) provide the services that the framework handles using JPA to serve the results. You define a repository in a way Spring can scan the project and find it:

<repositories base-package="com.acme.repositories" />

Thus, allowing you to use it in the context of a container or outside of it.

Now what exactly is Spring, JPA. Is Spring, JPA has added some more functionality (Interfaces) over JPA and still it is specified only or it is also a JPA provider?

Spring Data JPA provides a definition to implement repositories that are supported under the hood by referencing the JPA specification, using the provider you define.


The Java Persistence API, sometimes referred to as JPA, is a Java framework managing relational data in applications using the Java Platform, Standard Edition (JavaSE) and Java Platform, Enterprise Edition(JavaEE).

Persistence in this context covers three areas:

  • The API itself, defined in the javax.persistence package.

  • The Java Persistence Query Language (JPQL).

  • Object-Relational metadata.

    在这里输入图像描述

  • Spring Data JPA is part of the umbrella Spring Data project that makes it easier to implement JPA based repositories.

    Features:

  • Sophisticated support to build repositories based on Spring and JPA
  • Support for QueryDSL predicates and thus type-safe JPA queries
  • Transparent auditing of domain class
  • Pagination support, dynamic query execution, ability to integrate custom data access code
  • Validation of @Query annotated queries at bootstrap time
  • Support for XML based entity mapping
  • JavaConfig based repository configuration by introducing @EnableJpaRepositories

    在这里输入图像描述

  • JPA is the Java Persistence API, which is Java's standard API for object-relational mapping.

    JPA is only an specification - you need an implementation of it to be able to use it. Hibernate is one of the most well-known and most used implementations of JPA, but there are others, such as EclipseLink JPA.

    The Spring Framework is a large framework to help you write enterprise-grade software easier. It contains support for many Java technologies, including JPA.

    The Spring Framework consists of a collection of projects, and one of these projects is Spring Data.

    The goal of Spring Data is to make it easier to work with different kinds of databases, from traditional relational databases to NoSQL databases. Spring Data supports JPA via the Spring Data JPA subproject.

    To write a program that uses JPA, you need at least a JPA implementation, such as Hibernate.

    If you are using the Spring Framework for your application, you will most likely want to use Spring Data JPA together with Hibernate.

    This link should be helpful to understand the concept better:

    https://spring.io/blog/2011/02/10/getting-started-with-spring-data-jpa/

    链接地址: http://www.djcxy.com/p/44084.html

    上一篇: JPA @ Entity内的Bean注入

    下一篇: JPA与JPA:有什么区别?