我有这样的课程
- 状态类 -
public class Status implements java.io.Serializable {
private Integer id;
private String name;
private Set<Item> items = new HashSet<Item>(0);
}
- 项目类 -
public class Item implements java.io.Serializable {
private Integer itemId;
private Set<Status> statuses = new HashSet<Status>(0);
}
现在我需要获取状态为OK
我做过类似的事情,但它没有用
Status status = new Status();
Set<Status> stset = new HashSet<Status>();
stset.add(status)
List<Criterion> criterionList = new ArrayList<Criterion>();
criterionList.add(Restrictions.in("statuses", stset));
答案 0 :(得分:2)
如何尝试这样,
Criteria criteria = session.createCriteria(Item.class)
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
criteria.createAlias("statuses", "statuses");
criteria.add(Restrictions.eq("statuses.name", "OK"));
List<Item> items = criteria.list();