Entity Inside Spring Projection (no association)
Description: If, for some reason, you need an entity in your Spring projection (DTO), then this application shows you how to do it via an example. In this case, there are two entities, Author
and Book
, that have no materialized association between them, but, they share the genre
attribute. We use this attribute to join authors with books via JPQL. And, we want to fetch in a Spring projection the authors as entities, Author
, and the title
of the books.
Key points:
- define two unrelated entities (e.g.,
Author
andBook
) - define the proper Spring projection having
public Author getAuthor()
andpublic String getTitle()
- write a JPQL to fetch data