That's my repository: https://github.com/mtpx/SpringProject
I have UserDAOImpl class implementing UserDAO interface which extends CrudRepository
In controller I have 4 endpoints - findAllQuery&findByIdQuery - these methods works for me using @namedQuery and findAll&FindById - UserDAOImpl need implementation of these methods and by default they returning null, Can I use this methods without implementation? It works for me before i added UserDAO interface or only way to getAllUsers is create query with entity manager? Is any other option to use default JPA findAll method without implementing it in this project structure?
Remove the
@Override
List<User> findAll();
from your UserDAO, along with the implementation in UserDAOImpl. This will allow you to use the CrudRepository implementation.
Same stands for
save()
and
delete()
You can use methods without implementation if you are not overriding them. As you can see here the default implementation will return you Optional
Probably to maintain default CrudRepo methods You need to create a separate interface for your custom methods:
public interface UserDAO
extends CrudRepository<User, Integer>, UserDAOCustom
public interface UserDAOCustom{
public void customMethod();
}
and implements class for CustomDAO interface
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.