spring-data-jpa Repositories Finding a particular instance of an entity class by the identifier


Example

A particular instance of an entity class can be loaded as follows:

Foo foo = fooRepository.findOne(id);

The findOne method is provided by the CrudRepository interface. It expects an identifier that uniquely identifies an entity instance (for instance, a primary key in a database table). The Java type for the id parameter must match the type assigned to the entity attribute annotated with the JPA @Id annotation.

Invoking the findOne method results in the JPA query select foo from Foo foo where foo.[primary-key-column] = :id being executed on the underlying database.