Is there any difference when using Spring Data JPA keywords between:
List<SomeEntity> findBySomeCondition();
and
List<SomeEntity> findAllBySomeCondition();
Is there any difference when using Spring Data JPA keywords between:
List<SomeEntity> findBySomeCondition();
and
List<SomeEntity> findAllBySomeCondition();
findBy method is used if we want to find by name or some other criteria like
findByFirstName(String firstName);
findAll methods generally finds by providing specification
Please see docs below for more clarity:
http://docs.spring.io/spring-data/jpa/docs/1.4.3.RELEASE/reference/html/jpa.repositories.html
No, there is no difference between them, they will execute exactly the same query, the
All
part is ignored by Spring Data when deriving the query from the method name. The only important bit is theBy
keyword, anything following it is treated as a field name (with the exception of other keywords likeOrderBy
which incidentially can lead to some strange looking method names likefindAllByOrderByIdAsc
).This means something like this is perfectly valid:
And will execute exactly the same SQL query as:
or
Update: I'd never seen any official description of this behaviour in the documentation but in a recent blog post about the upcoming 2.0 release of Spring Data (Kay) it was explained: