【问题标题】:Query with nested constructor使用嵌套构造函数查询
【发布时间】:2016-07-27 18:19:31
【问题描述】:

当我使用我的自定义 DTO 使用嵌套构造函数尝试此查询时。

select new DTO.foo ( new DTO.boo( ... ) , new DTO.boo( ... ) ) from Foo

我收到了这个错误:

org.hibernate.hql.internal.ast.QuerySyntaxException: 
unexpected token: new near line 1, column 23 [ select new DTO.foo ( new DTO.boo( ... ) , .....

解决方案
由于我们不能在构造函数中包含构造函数,因为它在 JPQL 中是非法的,我们通过在此处遵循相同的方法解决此问题:https://stackoverflow.com/a/12742926/1383538

【问题讨论】:

  • 能不能把hibernate从log做的quer加进去
  • 这是一个QuerySyntaxException,所以还没有生成休眠查询

标签: java hibernate jpa


【解决方案1】:

这是非法的JPQL,根据JPQL BNF 表示法

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

构造函数中不能有构造函数(即constructor_item 不能是constructor_expression)。请参阅JPA 规范

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-03
    • 2023-04-03
    • 2014-06-11
    • 1970-01-01
    • 2021-07-17
    • 2012-12-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多