spring-data-jpa Repositories Finding all instances of an entity class with an attribute matching a specified value

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9

Example

All instances of an entity class with one of the class attributes matching a specified value can be retrieved as follows:

public interface FooRepository extends CrudRepository<Foo, Long> {
  List<Foo> findAllByName(String name);
}

Invoking the findAllByName method results in the JPA query select foo from Foo foo where foo.name = :name will be executed on the underlying database.

Points to note

  1. name must be an attribute on the Foo entity class.
  2. The method name must begin with find, get or read. Other keywords like select will not work.
  3. There is no guarantee on the order in which the results will be returned.


Got any spring-data-jpa Question?