21

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.

Community
  • 1
  • 1
Dipanshu Verma
  • 459
  • 3
  • 8
  • 22

2 Answers2

68

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.

Mathias Dpunkt
  • 11,594
  • 4
  • 45
  • 70
  • Thanks Mathias +1 for Maturity Model, which I never new existed. However I was looking for a little more bit of explanation on how is it tightly coupled, and how is Spring Data JPA more loosely coupled. I was looking for specific examples, if you can... – Dipanshu Verma Oct 30 '15 at 16:20
  • 2
    Here is a very good example application https://github.com/olivergierke/spring-restbucks it contains examples for spring-data-rest but also contains custom controllers. – Mathias Dpunkt Oct 31 '15 at 11:00
  • 3
    Plus 1 for mentioning the downside of tight coupling between API and db, and for mentioning Spring HATEOAS. – java-addict301 Feb 01 '19 at 21:35
0

look for hibernate framework for easily manage Java application to interact with the database https://www.javatpoint.com/hibernate-tutorial