Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The method for verifying IS NULL with a custom data type in Hibernate is to override the isNull() method in the custom type class.

The isNull() method should return true if the value of the custom type is null.

For example, if you have a custom type MyCustomType:

public class MyCustomType implements UserType {
    ...
    @Override
    public boolean isNull(Object value) {
        return value == null;
    } 
    ...
}

Then, you can use the IS NULL operator in HQL or Criteria API to verify if the value of the custom type is null:

List<MyEntity> entities = session.createQuery("FROM MyEntity e WHERE e.customProperty IS NULL").list();

Or:

Criteria criteria = session.createCriteria(MyEntity.class);
criteria.add(Restrictions.isNull("customProperty"));
List<MyEntity> entities = criteria.list();