我如何通过列表来过滤掉一些实体,我尝试了以下内容,但我得到了无法解析的属性:实体:MyEntity:
public List getEntities(Set<MyEntity> blockedEntities) {
Session session = getCurrentSession();
Criteria crit = session.createCriteria(MyEntity.class, "entity");
crit.add(Restrictions.not(Restrictions.in("entity", blockedEntities)));
return (ArrayList<MyEntity>) crit.list();
}
答案 0 :(得分:1)
尝试使用ID:
crit.add(Restrictions.not(Restrictions.in("entity.id", idsOfTheBlockedEntities)));
此外,您不应将结果转换为ArrayList<MyEntity>
,而应转换为List<MyEntity>
。