Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 迭代数组以创建hibernate条件语句_Java_Hibernate - Fatal编程技术网

Java 迭代数组以创建hibernate条件语句

Java 迭代数组以创建hibernate条件语句,java,hibernate,Java,Hibernate,假设我的数组有3个整数对象值=3,4,5 我需要创建如下所示的hibernate标准 criteria.add(Restrictions.and(Restrictions.not(Restrictions.eq( "stepId", new Integer(3))), Restrictions.and(Restrictions .not(Restrictions.eq("stepId", new Integer(4))), Restrictions

假设我的数组有3个整数对象值=3,4,5 我需要创建如下所示的hibernate标准

criteria.add(Restrictions.and(Restrictions.not(Restrictions.eq(
        "stepId", new Integer(3))), Restrictions.and(Restrictions
        .not(Restrictions.eq("stepId", new Integer(4))), Restrictions
        .not(Restrictions.eq("stepId", new Integer(5))))));
上面的标准是手动创建的,我想知道是否可以通过迭代来自动执行

for(Iterator iterator = integerArray.iterator; iterator.hasNext()){
    // create the criteria above
}
您可以在获取
数组
参数时使用限制

  Integer[] integerArray = ...
  criteria.add(Restrictions.and(Restrictions.not(
        Restrictions.in("stepId", integerArray)
  );
是的,您可以在循环中使用:

Disjunction disjunction = Restrictions.disjunction();
for(Iterator iterator = integerArray.iterator; iterator.hasNext()){
    disjunction.add(yourRestriction); //add your restirction here
}
criteria.add(disjunction );