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 'where 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With