Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/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,我有一个这样的简单问题 select id,status,c01,c02,c03 from mytable where criterion1 and criterion2 and criterion3 我需要添加另一个这样的过滤器 //In Java if(mytable.status=1){ criteria.add(Restrictions.eq("anotherFilter",anotherFilterValue)); } 但是状态值出现在查询中,我的意思是我可以在内存

我有一个这样的简单问题

select id,status,c01,c02,c03 from mytable
where 
criterion1 
and criterion2 
and criterion3
我需要添加另一个这样的过滤器

//In Java
if(mytable.status=1){
  criteria.add(Restrictions.eq("anotherFilter",anotherFilterValue));
}   
但是状态值出现在查询中,我的意思是我可以在内存中过滤,但是我希望能够直接在数据库中过滤

像订购用例一样,我可以使用一些方法来实现它吗

这可以帮助你

select id,status,c01,c02,c03 from mytable
  where 
    criterion1 = ?
    and criterion2 = ? 
    and criterion3 = ?
    and 
       ((status is null and anotherFilter = :valueToFilter) 
       or (status is not null))
标准api

//In Java
criteria.add(
    Restrictions.or(
         Restrictions.isNotNull("status"),
         Restrictions.and(
           Restrictions.eq("anotherFilter",anotherFilterValue),
           Restrictions.isNull("status")
         )
    )
);

表示找不到符号符号:方法或标准,逻辑表达式位置:类型标准的可变标准I修复了它,简单的打字错误。
//In Java
criteria.add(
    Restrictions.or(
         Restrictions.isNotNull("status"),
         Restrictions.and(
           Restrictions.eq("anotherFilter",anotherFilterValue),
           Restrictions.isNull("status")
         )
    )
);