【发布时间】:2015-08-04 23:16:26
【问题描述】:
如果我有一个名为 Person 的类
public class Person{
private int id;
private int age;
}
如何获取最大年龄的人对象?
当我使用 criteria.setProjection(Projections.max("age) ) 时,它会返回我的最大年龄,然后我应该找到这个年龄的人的条目。
我可以跳过查找最大年龄吗?并直接获取最大年龄的人。它可能看起来像,
person = criteria.somehow.setProjection().somehow.setMaxResults(1).uniqueResult();
我正在尝试找出执行此操作的方法,因为我担心如果我在 hibernate 中进行两次搜索,会浪费我的性能时间。
【问题讨论】:
-
我想获取最大年龄的 Person 对象
标签: java hibernate hibernate-criteria