Bug fix in querying for NULL entities