I'd like to create projection. There is no problem when DTO is flat:
class Projection {
String id;
String fieldA;
String fieldB;
Projection(String id, String fieldA, String fieldB){
...
}
}
then query will be:
SELECT new Projection(t.id, t.fieldA, t.fieldB) FROM Entity t WHERE t.id...
but I cannot create query for that Projection:
class Projection {
String id;
NestedObject nested;
Projection(String id, NestedObject nested){
...
}
}
class NestedObject {
String fieldA;
String fieldB;
NestedObject(String fieldA, String fieldB){
...
}
}
I tried like:
SELECT new Projection(t.id, (SELECT new NestedObject(n.fieldA, n.fieldB) FROM Entity n)) FROM Entity t WHERE t.id...
but does not work.
Two questions:
- Is it possible?
- If answer for 1 is yes, how should this query look like?