Reputation: 1885
I have used both approaches, but what's the difference and which is better?
Upvotes: 3
Views: 2505
Reputation: 17498
The choice really depends on your application requirements and developer preference.
In Simple Terms
If you need low-level control and flexibility, use EntityManager.
If you want high level of abstraction, use JpaRepository.
Use Case
EntityManager
JpaRepository
@Query
Upvotes: 0
Reputation: 90527
If your query is simple and basic enough such that it can be achieved by Spring data 's query generation feature , use Repository over entity manager will save you some times and effort.
If your query cannot be easily achieved by the query generation feature or you need to fine tune them , use entity manager which gives you the most of the flexibility.
For CRUD only, both of them are more or less the same as entity manager API itself is already clean and simple enough to use.
Upvotes: 3