我有类别列表。我需要一个排除 2,3 行的类别列表。我们可以通过使用 Criteria 和 Restriction 通过 hibernate 来实现吗?
最佳答案
你的问题有点不清楚。假设“Category”是根实体,“2,3”是 id(或类别的某些属性的值),您可以使用以下命令排除它们:
Criteria criteria = ...; // obtain criteria from somewhere, like session.createCriteria()
criteria.add(
Restrictions.not(
// replace "id" below with property name, depending on what you're filtering against
Restrictions.in("id", new long[] {2, 3})
)
);
使用DetachedCriteria
也可以完成同样的事情。
关于hibernate - 如何在Hibernate中使用限制和标准来实现 "not in"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1220901/