@SQLRestriction("xyz IS NULL") generates two SQL conditions

on @Entity class called “ParentEntity” which has

@SQLRestriction("xyz IS NOT NULL")
private Set<ChildEntity> children = new HashSet<>();

when I use to find the parent and its children
repository.findBySomeKey(key)
then single SQL condition is generated:

and (
or1_0.xyz IS NOT NULL
)
So far everything is ok.

when I use entityGraph like so:
var eg = getEntityGraphForNodes("children");
CriteriaBuilder criteriaBuilder = this.getEntityManager().getCriteriaBuilder();
CriteriaQuery<ParentEntity> criteriaQuery = criteriaBuilder.createQuery(this.getPojoClass());
Root<ParentEntity> root = criteriaQuery.from(this.getPojoClass());
Predicate predicate = criteriaBuilder.equal(root.get("someKey"), value);
criteriaQuery.where(predicate);
return this.getEntityManager()
.createQuery(criteriaQuery)
.setHint("javax.persistence.fetchgraph", eg)
.getSingleResult();

then I get following SQL condition:
left join
child or1_0
on ure1_0.id=or1_0.user_id
and (or1_0.xyz IS NOT NULL)
and (or1_0.xyz IS NOT NULL)
What I see as a bug is the duplicate IS NOT NULL.

There is a similar issue discussed on github:

1 Like

Could be a bug. Please try to create a reproducer with our test case template and if you are able to reproduce the issue, create a bug ticket in our issue tracker and attach that reproducer.

issue created:
https://hibernate.atlassian.net/browse/HHH-17854

1 Like