gpt4 book ai didi

Hibernate @Formula 构建查询不正确

转载 作者:行者123 更新时间:2023-12-04 22:36:04 27 4
gpt4 key购买 nike

我正在向字段添加公式:

@Formula(value = "(select count(*) from approvalGroup as a where a.isAccounting=true)")

但是查询失败了,因为 Hibernate 试图在我的对象上设置 'true' 一个字段。
异常(exception):
[ERROR] Unknown column 'approvalgr0_.true' in 'where clause'

如何告诉 Hibernate 这是一个常量值而不是它需要从实体对象中检索的值?

最佳答案

Josh,Hibernate 公式作为 native SQL(不是 HQL)应用,并且您的 DBMS 的 SQL 方言可能没有真正的关键字。尝试更改代码如下

@Formula(value = "(select count(*) from approvalGroup as a where a.isAccounting)")

还要使用 DB 列名称,而不是使用持久实体属性的名称。

关于Hibernate @Formula 构建查询不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6360352/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com