开发者

Hibernate @Formula building query incorrectly

开发者 https://www.devze.com 2023-03-13 00:34 出处:网络
I\'m adding a formula to a field: @Formula(value = \"(select count(*) from approvalGroup as a where a.isAccounting=true)\")

I'm adding a formula to a field:

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

But the query is failing because Hibernate is trying to make 'true' a field on my object.

Exception:

[ERROR] Unknown column 'approvalgr0_.true' in 'wher开发者_Python百科e clause'

How can I tell Hibernate this is a constant value and not something it needs to retrieve from the entity object?


Josh, Hibernate formulas are applied as native SQL (not HQL) and probably SQL dialect of your DBMS don't have true keyword. Try changing code as follows

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

Also use DB column names instead of using names of persistent entity properties.

0

精彩评论

暂无评论...
验证码 换一张
取 消