Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
why cant we override methods of jparepository interface such as findById(),and many more . why we need to create new interface for performing crud operations.

What I have tried:

i have tried to implement jparepository and try to override findAll() method but it throws exception.
Posted
Updated 6-Aug-19 7:33am
Comments
Richard MacCutchan 6-Aug-19 12:44pm    
What is jparepository and what error message do you see?
Null_Byte 6-Aug-19 13:01pm    
Jparepository is a interface of spring framework used to perform CRUD operations.
https://docs.spring.io/spring-data/jpa/docs/current/api/org/springframework/data/jpa/repository/JpaRepository.html
Null_Byte 6-Aug-19 13:02pm    
I got an exception and it display as "application failed to start ...."

1 solution

why cant we override methods of jparepository interface such as findById(),and many more. why we need to create new interface for performing crud operations.
This really is not a question relative to fixing you with a code issue; as you already know the issue. The answer to why this repository interface is designed the way it is can only really be answered by the people who built it.

My opinion why something would be done this way would simply be to make sure anyone trying to override the factories knows what they are doing; and if so, they already know how to write their own repositories and interfaces so it really isn't necessary to provide that ability within their code. It also makes it a heck of a lot easier to troubleshoot when someone who is not familiar with how you did something has to understand why it is not working the way it was designed to.

There are plenty of documented ways on how to create your own interfaces to do this:
1- java - Spring Data: Override save method - Stack Overflow[^]
2- Spring Data JPA Tutorial: Adding Custom Methods to All Repositories[^]
3- https://dzone.com/articles/customizing-spring-data-jpa[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900