When i try this query with nested constructor with my custum DTO.
select new DTO.foo ( new DTO.boo( ... ) , new DTO.boo( ... ) ) from Foo
I got this error :
org.hibernate.hql.internal.ast.QuerySyntaxException:
unexpected token: new near line 1, column 23 [ select new DTO.foo ( new DTO.boo( ... ) , .....
SOLUTION
Since we cannot have a constructor within a constructor because it's illegal in JPQL We resolve this issue by following the same approach over here : https://stackoverflow.com/a/12742926/1383538
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 |
identification_variable
You cannot have a constructor within a constructor (i.e constructor_item cannot be a constructor_expression). See the JPA spec
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With