I am using EMF and Teneo. I have an Employee class with a derived attribute. I also defined a Hibernate @Formula annotation for it as follows:
* @model
* default="0" transient="true" changeable="false"
* derived="true" ordered="false"
* annotation="teneo.jpa
* appinfo=' @Formula(\"select count(*) from Employee o where o.parent_e_id =e_id\")'"
I was expecting the query to fire whenever I load the Employee object by a call to .list().
However, the query to calculate the derived attribute never fires (checked the mysql log).
Any ideas on what I am doing wrong or any pointers on where to look?
I am answering to my own question since I have found the solution and someone else might need it
The attribute has to be defined as follows:
* @model default="0" derived="true" ordered="false"
* annotation="teneo.jpa
appinfo=' @Formula(\"(select count(*)
from Employee o where o.parent_e_id=e_id)\")'"
In other words, the attribute
Also the SQL statement should be in brackets since hibernate will generate a statement such as
select field1, field2, (select count (*) from Employe o where
o.parent_e_id_e_id) as fieldname from table1 ...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.