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

  1. I believe hibernate first translates your HQL query to SQL and only after that it tries to bind your parameters. Which means that it won’t be able to rewrite query from param = ? to param is null.

  2. Try using Criteria api:

    Criteria c = session.createCriteria(CountryDTO.class);
    c.add(Restrictions.eq("type", type));
    c.add(status == null ? Restrictions.isNull("status") : Restrictions.eq("status", status));
    List result = c.list();
    

Leave a Comment