I'm using CrudRepository to fetch Persons from database.
Is it possible to only fetch certain fields from the db, instead of the full entity, using a CrudRepository mapping method?
Example: I only want to extract all lastname column fields:
interface PersonRepository extends CrudRepository<Person, Long> {
//of course this is invalid
List<String> findAllLastname();
}
@Entity
public class Person {
@Id
private Long id;
private String firstname, lastname;
}
findAllLastname() is of course not valid, but can I achieve this?