I'm trying to map a one to "zero or one" relationship in Hibernate. I think I may have found a way using a many-to-one.
class A {
private B b;
// ... getters and setters
}
class B {
private A a;
}
Class A's mapping specifies:
<many-to-one name="b" class="B"
insert="false" update="false"
column="id" unique="true"/>
and Class B's mapping specifies:
<one-to-one name="a" class="A" constrained="true"/>
What I would like is for b to be null when no matching row for B was found in the database. So I can do this (in class A):
if (b == null)
However, it seems that b is never null.
What can I do about this?