Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.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 如何为2种情况(x和Y)或(a和b))设置Hibernate标准_Java_Hibernate - Fatal编程技术网

Java 如何为2种情况(x和Y)或(a和b))设置Hibernate标准

Java 如何为2种情况(x和Y)或(a和b))设置Hibernate标准,java,hibernate,Java,Hibernate,我想使用Hibernate创建的SQL如下: SELECT * FROM tableName WHERE ...(another condition I have already handled here) AND ((billingCompleted = 0 AND terminationDate IS NULL) OR (billingCompleted = 0 AND terminationDate IS NOT NULL)) 到目前为止,我的尝试没有成功: item

我想使用Hibernate创建的SQL如下:

SELECT *
FROM tableName
WHERE ...(another condition I have already handled here)
    AND ((billingCompleted = 0 AND terminationDate IS NULL)
      OR (billingCompleted = 0 AND terminationDate IS NOT NULL))
到目前为止,我的尝试没有成功:

itemCriteria.add(Restrictions.and(
    Restrictions.or(
        (Restrictions.eq("billingCompleted", new Integer(0)), 
         Restrictions.isNotNull("terminationDate")),    
        (Restrictions.eq("billingCompleted", new Integer(0)), 
         Restrictions.isNull("terminationDate")))))); 

我需要如何格式化才能将其设置为适合Hibernate?

严格按照您的要求编写,限制是:

Restrictions.and(
        Restrictions.or(
                Restrictions.and(Restrictions.eq("billingCompleted", 0),  Restrictions.isNotNull("terminationDate")),
                Restrictions.and(Restrictions.eq("billingCompleted", 0), Restrictions.isNull("terminationDate"))));
但是,您的表达式可以简化为

Restrictions.and(Restrictions.eq("billingCompleted", 0));
因为您希望
billingCompleted=0
terminationDate为null或terminationDate不为null
。最后一个总是计算为
true
X和true==X
,因此我们可以简单地删除该条件