hibernate条件按列表过滤对象

时间:2012-06-12 08:49:35

标签: hibernate criteria

我如何通过列表来过滤掉一些实体,我尝试了以下内容,但我得到了无法解析的属性:实体: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();
}

1 个答案:

答案 0 :(得分:1)

尝试使用ID:

crit.add(Restrictions.not(Restrictions.in("entity.id", idsOfTheBlockedEntities)));

此外,您不应将结果转换为ArrayList<MyEntity>,而应转换为List<MyEntity>