Hibernate: How to set NULL query-parameter value with HQL?

前端 未结 10 748
感情败类
感情败类 2020-12-01 07:23

How can I set a Hibernate Parameter to \"null\"? Example:

Query query = getSession().createQuery(\"from CountryDTO c where c.status = :status  and c.type =:t         


        
10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 07:37

    You can use

    Restrictions.eqOrIsNull("status", status)
    

    insted of

    status == null ? Restrictions.isNull("status") : Restrictions.eq("status", status)
    

提交回复
热议问题