I have two classes with a bi-directional @OneToOne mapping to each other.
Class A {
@OneToOne(fetch = FetchType.Lazy, mappedBy="a")
private B b;
}
Class B {
@OneToOne(fetch = FetchType.Eager)
private A a;
}
I need to write code to retrieve all instance of B which to do not have an instance of A associated with them. I also need to write a similar query for all A which have no B.
I have tried:
Criteria criteria = getSession().createCriteria(B.class)
criteria.add(Restrictions.isNull("a")
but this seems to always return null. Thoughts?
This should work, for both directions: