Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.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条件eqOrIsNull返回错误值_Java_Database_Hibernate - Fatal编程技术网

Java Hibernate条件eqOrIsNull返回错误值

Java Hibernate条件eqOrIsNull返回错误值,java,database,hibernate,Java,Database,Hibernate,我有一个映射到db的类。 这是我使用hibernate的criteria API函数: public List<Department> getDepartmentBy(Account account) { return createCriteria(Department.class) .add(Restrictions.eq("account ", account)) .add(Restrictions.eqOrIsNull("

我有一个映射到db的类。 这是我使用hibernate的criteria API函数:

public List<Department> getDepartmentBy(Account account)
{
    return createCriteria(Department.class)
            .add(Restrictions.eq("account ", account))
            .add(Restrictions.eqOrIsNull("archive", false))
            .list();
}
是虫子吗?还是我使用了错误的API标准

UPD:准确解释

我在数据库中有8条记录,存档p等于null。当我想要在“存档”字段中选择带有“false”或null的记录时,我使用
add(Restrictions.eqOrIsNull(“存档”,false))
。我需要NULL或false的记录。但是当我添加
.add(Restrictions.eqOrIsNull(“archive”,false))
时,我得到的结果是0条记录。

您使用了错误的标准API,
eqOrIsNull()的源代码。


只有当
value==null
时,它才会添加null检查。您传递
值==false

你能描述一下你面临的具体问题吗?添加更新,但得到正确的答案我认为这是最适合我的方法。返回值或如果值等于null,则返回null。谢谢@不客气。这是一种不好的限制方法,因为它经常使用不当。
private Account _account;
private boolean _archive = false;

@ManyToOne
@JoinColumn(name = "account_l", nullable = false)
public Account getAccount ()
{
    return _account;
}

public void setAccount(Account account)
{
    _account = account;
}

@Column(name = "archive_p")
public boolean isArchive()
{
    return _archive;
}

public void setArchive(boolean archive)
{
    _archive = archive;
}
public static Criterion eqOrIsNull(String propertyName, Object value) {
    return value == null
            ? isNull( propertyName )
            : eq( propertyName, value );
}