Hibernate: An interface projection is even less code

Spring Data implements the interface for you from the selected columns.

Code
interface OrderView {
    Long getId();
    String getReference();
    BigDecimal getTotal();
}

interface OrderRepository extends JpaRepository<Order, Long> {
    List<OrderView> findByStatus(Status status);
}
Output
Spring generates a proxy implementing OrderView,
and selects only id, reference and total.
Advertisement

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-11