Is it possible to have a Spring Data JPA repository method like this:
User findByEmailOrUserName(String usernameOrEmail);
The above method name doesn't work as Spring Data JPA throws an exception when it tries to find the second parameter that needs to be bound to second property name in the method.
I want a method name that will translate to select t from User t where t.email = :usernameOrEmail OR t.userName = :usernameOrEmail
Does the method name queries have such a possibility?
The main advantage of JPA over JDBC for developers is that they can code their Java applications using object-oriented principles and best practices without having to worry about database semantics.
Spring Data JPA aims to significantly improve the implementation of data access layers by reducing the effort to the amount that's actually needed. As a developer you write your repository interfaces, including custom finder methods, and Spring will provide the implementation automatically.
Spring Data JPA is a sub-project of Spring Data and provides an abstraction over the Data Access Layer using Java Persistence API and ORM implementations like Hibernate.
Crud Repository doesn't provide methods for implementing pagination and sorting. JpaRepository ties your repositories to the JPA persistence technology so it should be avoided. We should use CrudRepository or PagingAndSortingRepository depending on whether you need sorting and paging or not.
With current latest version of Spring Data JPA (v1.10.2), this is not possible. I don't see any such requests for future versions either.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With