Hibernate @Formula building query incorrectly
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.
精彩评论