Is there an out of the box way to create such a projection with nested fields like, for example, List items; ? And if here is no way to do that what do you suggest to do when you actually need to build such a projection?
Hi Ajay, No, there is no support for nested DTO projections. You could add a constructor to your top-level class and instantiate the nested DTO objects in there. But please keep in mind that Hibernate applies the constructor to each record in the result set as the database returns it. This result set is a flat data structure. You can't access the full list of a to-many association in the constructor because the database returns it as author1-book1, author1-book2, author1-book3, ...
@@Thorben-Janssen thank you for the reply. Yes the result set is a flat data structure. My response format is a bit complex. I used the constructor to create a temporary response and converted it to my desired response format using mapstruct. Your blog has been very much useful. Thank you!
Good day, everyone!!! Thank you very much, very needed information
Is there an out of the box way to create such a projection with nested fields like, for example, List items; ?
And if here is no way to do that what do you suggest to do when you actually need to build such a projection?
Incredibly helpful video!
Very informative. Thanks.
Great stuff!
Much needed information. Do they support nested DTO projection? Like objects with collection objects.
Hi Ajay,
No, there is no support for nested DTO projections.
You could add a constructor to your top-level class and instantiate the nested DTO objects in there. But please keep in mind that Hibernate applies the constructor to each record in the result set as the database returns it. This result set is a flat data structure. You can't access the full list of a to-many association in the constructor because the database returns it as author1-book1, author1-book2, author1-book3, ...
@@Thorben-Janssen thank you for the reply. Yes the result set is a flat data structure. My response format is a bit complex. I used the constructor to create a temporary response and converted it to my desired response format using mapstruct.
Your blog has been very much useful. Thank you!
Hi, how can we verify that Dto projections are more performative than eg entity projections? Thanks.
@ThorbenJanssen How to use the nested DTO data Projection
Hello Thorben Janssen,
Please provide the entire source code
sympathisch
The Criteria API is awfull!
Haha, yes the Criteria API is special ;)