Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 'where clause'

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

like image 410
Josh Avatar asked Dec 17 '22 12:12

Josh


1 Answers

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.

like image 79
Trader001 Avatar answered Dec 28 '22 07:12

Trader001