Reputation: 99
I have JPA entities with fields like String mName. When using Spring data repositories I want to use e.g findByName instead of findByMName. I know that I can set the entity access to on properties instead of fields but that has other drawbacks.
Upvotes: 0
Views: 29
Reputation: 3089
Use this way in your repository
@Query("SELECT t FROM Todo t where t.mName = ?1")
Todo findByName(String mName);
Upvotes: 2
Reputation: 793
You can create default method in Interface Repository like this :
@Repository
public interface TodoRepository extends CrudRepository<Todo, Integer> {
default Optional<Todo> findByName(String mName){
return findByMName(mName);
}
}
Then you can call repo.findByName(mName).
Upvotes: 1