Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between spring-boot-starter-data-rest and spring-boot-starter-data-jpa

I am trying to understand various dependencies of spring boot. I have come across three of them:

  1. spring-boot-starter-data-rest
  2. spring-boot-starter-data-jpa
  3. spring-boot-starter-data-jdbc

I would like to know the difference between the three. Tried searching online documents, which say the three are almost related to spring data. how to resolve the confusion?

To add in here I have also found an another dependency spring-boot-starter-web-services. I think it supports both SOAP and REST. Its just my assumption, I waiting for an explanation

like image 663
Learner Avatar asked Dec 09 '22 23:12

Learner


2 Answers

spring-boot-starter-data-jpa is used to access your database with JPA (Java Persistence API)

spring-boot-starter-data-jdbc is used to access your data with jdbc (Java Database Connectivity)

the difference between JPA and JDBC is the level of abstraction. JDBC is more low level, JPA is more 'magic'

and spring-boot-starter-data-rest is used to provide Rest Endpoints on top of your Spring Data repositories.

To do this, you just annotate your spring data repository with a RepositoryRestResource annotation and direct Spring MVC creates the Restful endpoints.

@RepositoryRestResource(collectionResourceRel = "people", path = "people")
public interface PersonRepository extends PagingAndSortingRepository<Person, Long> {

  List<Person> findByLastName(@Param("name") String name);

}

This is very handy if you do very CRUD like (Create, Read, Update, Delete) applications.

like image 96
Andreas Radauer Avatar answered Mar 16 '23 00:03

Andreas Radauer


JPA means "Java Persistence API". It's for querying or saving data in relational databases using object-relational mapping.

REST means "REpresentational State Transfer". It's a style for creating web services that leverages HTTP verbs, a simpler alternative to SOAP.

JDBC starter uses the Spring JdbcTemplate to query or save data in relational databases without relying on object-relational mapping. You write SQL and ask the JdbcTemplate class to execute it in the database using JDBC.

I would say JPA and JDBC starters should be mutually exclusive: either one or the other.

You use REST only if you're writing web services. These may or may not query or persist data in a relational database. I would expect to see both the REST starter and a persistence starter in a pom if a REST service needed persistent data.

Three very different starters.

You ask why Spring Boot has a REST data starter parent that combines the two. In a word: convenience.

like image 32
duffymo Avatar answered Mar 16 '23 00:03

duffymo