Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring data rest vs spring data jpa

Tags:

I have had a look at the following question

What are the advantages of using Spring Data REST over Spring Data JPA?

It doesn't quite cater to my needs. My DB is on MYSQL, I chose Spring-Data-JPA implementation. What are all the added advantages that REST can give me which I wont find in simple Spring-Data-JPA? For example if tomorrow, I decide to implement a cache b/w my business and Database module, in which case would I have to write lesser code? Which would be easily configurable? Which would be more flexible and how?

Also, if I am using both REST and JPA in a new application, what design principles do I break?

I am looking forward to the answers from an architecture perspective. Thanks in advance.

like image 398
Dipanshu Verma Avatar asked Oct 29 '15 19:10

Dipanshu Verma


People also ask

What is difference between Spring Data JPA and Spring Data rest?

A spring alternative to spring-data-rest is using spring MVC directly to create a REST API on your own. Spring-data-jpa would still be used to implement the data access layer. Spring MVC is very powerful and is used by spring-data-rest under the hood. This gives you full control of the REST layer.

What is the Spring Data rest?

Spring Data REST is part of the umbrella Spring Data project and makes it easy to build hypermedia-driven REST web services on top of Spring Data repositories.

Should I use JpaRepository or CrudRepository?

Crud Repository doesn't provide methods for implementing pagination and sorting. JpaRepository ties your repositories to the JPA persistence technology so it should be avoided. We should use CrudRepository or PagingAndSortingRepository depending on whether you need sorting and paging or not.

Why Spring Data rest is used?

Spring Data REST BenefitsIn order to make it easier for the clients to discover the HTTP access points exposed by the repositories, Spring Data REST uses hypermedia driven endpoints. Spring Data REST is a web application that can be added using its dependency.


1 Answers

Basically I think your question is not completely to the point. I think you have not completely found your way through the spring project jungle - so I try to give a little orientation here.

Spring-data-jpa is the spring way to access data using JPA. You could use spring-data-rest on top of spring-data-jpa to create a REST-API layer with no code on top of your repositories and entities.

And what spring-data-rest can do for you is just amazing. It is the fastest way to create a REST API on top of your JPA layer. And it is also highly customizable. But I think it has it's limits. The most significant weakness is the tight coupling between entities and API. Usually you would like to have a little decoupling between these layers. But it is a great piece of software. If you need to be fast and want to write the minimal amount of code go for spring data rest.

A spring alternative to spring-data-rest is using spring MVC directly to create a REST API on your own. Spring-data-jpa would still be used to implement the data access layer. Spring MVC is very powerful and is used by spring-data-rest under the hood. This gives you full control of the REST layer.

I also want to mention spring HATEOAS - it is just a module on top of spring mvc and it gives you the tools to create a hypermedia driven REST API - so you can go for a maturity level 3 of the Richardson Maturity Model - it is also used by spring-data-rest internally.

like image 155
Mathias Dpunkt Avatar answered Oct 01 '22 08:10

Mathias Dpunkt