Skip to content
Advertisement

Convert to DTO from join selection

I have these two tables

enter image description here

And I am using this query to get the results

JavaScript

So far this is the only way I could retrieve the results and actually use them later. To use them I am using this code currently

JavaScript

But using it that way seems odd to me. Is there a better way to directly map the result to a DTO or something…

Advertisement

Answer

There are some options. The most straighforward way would be to define a projection Interface, like:

JavaScript

With that you could change your query return type to:

JavaScript

The rest would then be using getters.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement