Incorrect Hibernate @Formula building request

I add the formula to the field:

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

But the request does not work, because Hibernate is trying to make a "true" field on my object.
An exception:

 [ERROR] Unknown column 'approvalgr0_.true' in 'where clause' 

How can I say that Hibernate is a constant value, not what it needs to extract from an entity object?

+4
source share
1 answer

Josh, Hibernate formulas are used as native SQL (not HQL), and probably the SQL dialect of your DBMS does not have the true keyword. Try changing the code as follows

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

Also use database column names instead of using constant property names of the object.

+11
source

All Articles