给定映射的休眠类:
@Entity
public class MyTestClass {
/* id and stuff */
private Integer aValue;
private Integer bValue;
}
您可以使用 HQL 执行以下操作:
Query query
= getCurrentSession().createQuery("select aValue * bValue from MyTestClass");
List<Double> resultList = query.list;
并得出计算结果。
是否可以使用 Criteria API 做类似的事情?我还没有找到一种通过 Criteria API 使用数学运算的方法。我们有 sum、avg 等聚合函数,但没有基本的数学运算符?