You*_*sef 2 java hibernate jpa
当我使用custum DTO尝试使用嵌套构造函数进行此查询时。
select new DTO.foo ( new DTO.boo( ... ) , new DTO.boo( ... ) ) from Foo
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
org.hibernate.hql.internal.ast.QuerySyntaxException:
unexpected token: new near line 1, column 23 [ select new DTO.foo ( new DTO.boo( ... ) , .....
Run Code Online (Sandbox Code Playgroud)
解决方案
由于在构造函数中不能包含构造函数,因为它在中是非法的,因此JPQL我们在此处采用相同的方法来解决此问题:https : //stackoverflow.com/a/12742926/1383538
JPQL根据JPQL BNF符号,这是非法的
constructor_expression ::= NEW constructor_name ( constructor_item {, constructor_item}* )
constructor_item ::= single_valued_path_expression | scalar_expression | aggregate_expression |
identification_variable
Run Code Online (Sandbox Code Playgroud)
构造函数中不能包含构造函数(即constructor_item不能为constructor_expression)。见JPA规格
| 归档时间: |
|
| 查看次数: |
698 次 |
| 最近记录: |