I am converting to hibernate 5.2.4 and to use CriteriaQuery. Have a slight issue in testing for a null join on a file. This is what I was doing before which worked.
@Entity
public class MyClass {
....
@ManyToOne(..)
public MyDetail getMyDetail() {
return myDetail;
}
}
Criteria criteria = session.createCriteria(MyClass.class);
criteria.createAlias("myDetail", "md");
criteria.add(Restrictions.isNotNull("myDetail"));
I have been checking like this and sometimes it does not work:
andPredicate = builder.and(andPredicate, builder.isNotNull(
root.get(MyClass_.myDetail)));
Is there a correct way to do this? I have tried to create the join and test for a null but this also does not work:
Join<MyClass, MyDetail> myJoin = root.join(MyClass_.myDetail);
andPredicate = builder.and(andPredicate, myJoin.isNotNull());
Thanks.