简体   繁体   中英

Difference between spring-data-jpa and spring-boot-starter-data-jpa

This may not be the best question to ask, but I noticed there are 2 Spring JPA for Spring boot. How are they different. Currently I am trying to setup SpringBoot 1.5.3 project along with hibernate. I remember I had setup Springboot with JPA earlier with spring-boot-starter-data-jpa.

Most of the online examples I have seen as well as starter.spring.io provides below dependency for spring jpa.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

But in one of the existing project I came across spring-data-jpa

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

Doing a bit of google did not give me if they are different or not.

In all my previous projects where I added JPA was though JPA 2.1/Hibernate that is why I am a bit unsure which of the 2 to use in my new SpringBoot application.

As stated in the docs , the starter one is a convenient inliner for all required dependencies for this particular library, ie includes other dependencies in itself, instead of you writing those manually.

Look into the spring-boot-starter-data-jpa pom.xml , you will see there it includes spring-data-jpa as a dependency among many others.

Spring Boot Starters are a set of convenient dependency descriptors that you can include in your application. You get a one-stop-shop for all the Spring and related technology that you need without having to hunt through sample code and copy paste loads of dependency descriptors. For example, if you want to get started using Spring and JPA for database access just include the spring-boot-starter-data-jpa dependency in your project, and you are good to go.

Check the pom.xml for spring-boot-starter-data-jpa here: https://github.com/spring-projects/spring-boot/blob/master/spring-boot-starters/spring-boot-starter-data-jpa/pom.xml

Read the description tag which says: "Starter for using Spring Data JPA with Hibernate".

So spring-boot-starter-data-jpa uses Spring Data JPA with Hibernate as the implementation. This is hard-coded, so to speak.

If you now check the pom.xml for spring-data-jpa, it is implementation-agnostic. And to use Spring Data JPA in any project, one must provide the implementation to use. Not doing that will give you an error.

Spring Data JPA documentation states that it currently supports Hibernate 5, (Apache) OpenJPA 2.4 and EclipseLink 2.6.1. Read here: https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#new-features.1-10-0

Spring Boot provides spring-boot-starter-data-jpa starter to connect spring application with relational database efficiently. The starter have additional dependencies.

spring-data-jpa is used as a dependency for spring-boot-starter-data-jpa . Since you use spring boot version 1.5.3, you may have a look at here .

spring-data-jpa , part of the larger Spring Data family, makes it easy to easily implement JPA based repositories. This module deals with enhanced support for JPA based data access layers. It makes it easier to build Spring-powered applications that use data access technologies.

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