- Type Parameters:
ID- the type of the projection's primary key, or Void if the projection has no primary key.
public interface Projection<ID>
Marker interface for record-based projections.
This interface is leveraged by ProjectionRepository to provide built-in read operations.
Projections represent read-only data structures, such as database views or tables defined by custom
SQL queries using the ProjectionQuery annotation.
Usage examples:
Define a projection record based on the basket_summary_view view, with a basket_id primary
key.
@DbTable("basket_summary_view")
record BasketSummary(@PK @FK Basket basket, int itemCount, BigDecimal totalPrice) implements Projection<Integer> {}
Then, you can use the projection in a query like this:
var baskets = ...
List<BasketSummary> summaries = ORM(dataSource).projection(BasketSummary.class)
.select()
.where(baskets) // Type-safe.
.getResultList();
Or use it as a foreign key in an entity:
record User(@PK int id, @FK("basket_id") BasketSummary basketSummary) implements Entity<Integer> {}
Then, you can query all users having a basket with at least 1 item:
List<User> users = ORM(dataSource).projection(User.class)
.select()
.where(User_.basketSummary.itemCount, GREATER_THAN, 0) // Type-safe metamodel.
.getResultList();
- See Also: