3

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

2
  • Can you add the quer made by hibernate from log Commented Jul 27, 2016 at 18:25
  • it's a QuerySyntaxException so there is no generated hibernate query yet Commented Jul 27, 2016 at 18:26

1 Answer 1

6

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

Sign up to request clarification or add additional context in comments.

1 Comment

Any ideas on how to go around it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.