[英]How to use @Formula annotation in Teneo/EMF
I am using EMF and Teneo. 我正在使用EMF和Teneo。 I have an Employee class with a derived attribute.
我有一个带有派生属性的Employee类。 I also defined a Hibernate @Formula annotation for it as follows:
我还为它定义了一个Hibernate @Formula注释,如下所示:
* @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(). 我希望通过调用.list()加载Employee对象时都会触发查询。
However, the query to calculate the derived attribute never fires (checked the mysql log). 但是,用于计算派生属性的查询从不触发(检查mysql日志)。
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 SQL语句也应放在方括号中,因为hibernate会生成如下语句:
select field1, field2, (select count (*) from Employe o where
o.parent_e_id_e_id) as fieldname from table1 ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.