我该如何编写Hibernate Criteria

时间:2012-04-25 20:32:03

标签: hibernate hql hibernate-mapping hibernate-criteria

我们可以在标准中添加限制吗?

对于HQL-1#

select activity from EmployeeActivity activity
   join activity.activityStep as step
   where
   activity.currentStep = 1;

Criteria ctr = getSession().createCriteria(EmployeeActivity.class)
   .createCriteria("activityStep")//Where activityStep is the another entity which is joined
   .add(Restrictions.eq("currentStep", 1))

但是我应该如何编写以下HQL查询?而且,最佳做法是什么。

select activity from EmployeeActivity activity
   join activity.activityStep as step
   where
   activity.currentStep = step.stepNumber;

1 个答案:

答案 0 :(得分:1)

虽然我不确定查询应该做什么

Criteria ctr = getSession().createCriteria(EmployeeActivity.class)
   .createAlias("activityStep", "step")
   .add(Restrictions.propertyEq("currentStep", "step.stepNumber"));