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

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

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.



Got any spring-data-jpa Question?