All instances (objects) of an entity class can be loaded from the underlying database table as follows (akin to retrieving all rows from the table):
Iterable<Foo> foos = fooRepository.findAll();
The findAll
method is provided by the CrudRepository
interface. It returns an Iterable
instead of a more concrete type like List
or Set
because some implementations of the interface may be unable to return a Collection
type and therefore using a Collection
type for the returned value will result in loss of functionality for them.
Invoking the findAll
method results in the JPA query select foo from Foo foo
being executed on the underlying database.