1

Which option is better out of the two so that i can use most of the hibernate feature in a spring boot project.

1) Custom Repositories + Hibernate Code 2) Extending JpaRepository or CrudRepository interfaces.

Does Using Spring Data JPA provides same control (e.g cache, criteria queries etc) ?

Need your valuable suggestions / comments.

  • You might want to take a look at https://stackoverflow.com/questions/42470060/spring-data-jdbc-spring-data-jpa-vs-hibernate/42488593#42488593 and similar questions – Jens Schauder Jan 02 '20 at 14:30

3 Answers3

5
  1. You should prefer Extending JpaRepository or CrudRepository interfaces. As will help you to reduce boilerplate code from your project.
  2. Spring Boot framework provides flexibility to use the Custom Repositories so that you can implement functionality not supported by the JpaRepository/CrudRepository.
  3. There are no specific guidelines to use both of the ways. You can find the discussion for the same in What's the difference between JPA and Hibernate?
  4. You can implement caching with both the approaches with the same ease, but it will be altogether different than the above 2 points. It needs a detailed answer.
  • Seems that point 3 is taking us somewhere else. Will be helpful if you have any links for enable caching in jpa repository or crud repository. – Nishant Gupta Jan 02 '20 at 10:22
  • 1
    To enable caching with the spring boot you can use below link with elaborated steps: [https://www.baeldung.com/spring-cache-tutorial](https://www.baeldung.com/spring-cache-tutorial) – PANKAJ PUROHIT Jan 02 '20 at 10:34
1

JPA Repo is the advanced version for hibernate and custom repositories where you can do all the caching and criteria in it. JPA has 2 levels of caching. The first level of caching is the persistence context. The JPA Entity Manager maintains a set of Managed Entities in the Persistence Context.

Dinu
  • 600
  • 3
  • 6
  • 27
1

There is some info here - https://www.baeldung.com/spring-data-criteria-queries on criteria queries. I don't know about cache queries though.