title: Hibernate one to zero or one mapping
body: <p>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.  </p>
  
  <pre><code>class A {
    private B b;
    // ... getters and setters
  }
  
  class B {
    private A a;
  }
  </code></pre>
  
  <p>Class A's mapping specifies:</p>
  
  <pre><code>&lt;many-to-one name="b" class="B" 
  insert="false" update="false" 
  column="id" unique="true"/&gt;
  </code></pre>
  
  <p>and Class B's mapping specifies:</p>
  
  <pre><code>&lt;one-to-one name="a" class="A" constrained="true"/&gt;
  </code></pre>
  
  <p>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):</p>
  
  <pre><code>if (b == null)
  </code></pre>
  
  <p>However, it seems that b is never null.</p>
  
  <p>What can I do about this?</p>