我在字段中添加公式:
@Formula(value = "(select count(*) from approvalGroup as a where a.isAccounting=true)")
但查询失败了,因为Hibernate试图在我的对象上设置'true'字段 例外:
[ERROR] Unknown column 'approvalgr0_.true' in 'where clause'
我如何告诉Hibernate这是一个常量值而不是它需要从实体对象中检索的东西?
答案 0 :(得分:11)
Josh,Hibernate公式应用为本机SQL(不是HQL),并且DBMS的SQL方言可能没有 true 关键字。尝试更改代码如下
@Formula(value = "(select count(*) from approvalGroup as a where a.isAccounting)")
还使用DB列名而不是使用持久性实体属性的名称。