Skip to content

Latest commit

 

History

History
25 lines (18 loc) · 2.47 KB

File metadata and controls

25 lines (18 loc) · 2.47 KB

How To Enrich DTO With Virtual Properties Via Spring Projections

Note: You may also like to read the recipe, "How To Create DTO Via Spring Data Projections"

Description: This is an application sample that fetches only the needed columns from the database via Spring Data Projections (DTO) and enrich the result via virtual properties.

Key points:

  • we fetch from the database only the author name and age
  • in the projection interface, AuthorNameAge, use the @Value and Spring SpEL to point to a backing property from the domain model (in this case, the domain model property age is exposed via the virtual property years)
  • in the projection interface, AuthorNameAge, use the @Value and Spring SpEL to enrich the result with two virtual properties that don't have a match in the domain model (in this case, rank and books)

Output example:


If you need a deep dive into the performance recipes exposed in this repository then I am sure that you will love my book "Spring Boot Persistence Best Practices"If you need a hand of tips and illustrations of 100+ Java persistence performance issues then "Java Persistence Performance Illustrated Guide" is for you.