Youssef Youssef - 1 year ago 91
Java Question

Query with nested constructor

When i try this query with nested constructor with my custum DTO.

select new ( new ... ) , new ... ) ) from Foo

I got this error :

unexpected token: new near line 1, column 23 [ select new ( new ... ) , .....


Since we cannot have a constructor within a constructor because it's illegal in
We resolve this issue by following the same approach over here :

Answer Source

That is illegal JPQL, as per the JPQL BNF notation

constructor_expression ::= NEW constructor_name ( constructor_item {, constructor_item}* )
constructor_item ::= single_valued_path_expression | scalar_expression | aggregate_expression |

You cannot have a constructor within a constructor (i.e constructor_item cannot be a constructor_expression). See the JPA spec

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download