如何实现“不在”通过在Hibernate中使用限制和标准? [英] How to achieve "not in" by using Restrictions and criteria in Hibernate?

查看:84
本文介绍了如何实现“不在”通过在Hibernate中使用限制和标准?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类别列表。我需要排除2,3行的类别列表。我们可以通过使用Criteria和Restriction来实现hibernate吗?解析方案

你的问题有点不清楚。假设类别是一个根实体,2,3是ids(或类别的某些属性值),您可以使用以下内容排除它们:

 Criteria criteria = ...; //从某处获取标准,如session.createCriteria()
criteria.add(
Restrictions.not(
/ /使用属性名替换下面的id,具体取决于你对
进行过滤的限制.in(id,new long [] {2,3))

) ;

可以用 DetachedCriteria 完成。

I have list of category. I need a list of category by excluding 2,3 row. Can we achieve through hibernate by using Criteria and Restriction?

解决方案

Your question is somewhat unclear. Assuming "Category" is a root entity and "2,3" are ids (or values of some property of the category") you can exclude them using the following:

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})
  )
);

Same can be done with DetachedCriteria.

这篇关于如何实现“不在”通过在Hibernate中使用限制和标准?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆