title: Hibernate: optional many-to-one with not-null columns
body: <p>I've got an optional many-to-one relationship between two classes. Hibernate translates the property to be optional by setting the foreign keys to null.</p>
  
  <p>My db-schema does not allow the columns to be null. The property to be optional is represented by the default-value of these columns.</p>
  
  <pre><code>&lt;class name="sth.Alpha" ...&gt;
      ....
      &lt;many-to-one name="beta" not-found="ignore" class="sth.Beta" insert="true" update="true"&gt;
          &lt;column name="a1/&gt;
          &lt;column name="a2/&gt;
      &lt;/many-to-one&gt;
  &lt;/class&gt;
  
  &lt;class name="sth.Alpha" ...&gt;
      &lt;composite-id&gt;
          &lt;key-property name="b1" type="int"&gt;
              &lt;column name="b1" precision="8" scale="0"/&gt;
          &lt;/key-property&gt;
          &lt;key-property name="b2" type="int"&gt;
              &lt;column name="b2" precision="8" scale="0"/&gt;
          &lt;/key-property&gt;
      &lt;/composite-id&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p>selecting data is no problem because of <code>not-found="ignore"</code> in the may-to-one-tag it will result in a <code>null</code>-<code>beta</code>-object. But if I want to insert an <code>Alpha</code>?  with <code>beta</code> set to <code>null</code>. I get an Exception, that it is not possible to insert <code>null</code> to <code>a1</code> and <code>a2</code>.</p>
  
  <p>I get rid of that problem if I set <code>insert</code> and <code>update</code> to false. But this results in not saving the relationship if it is set.</p>
  
  <p>Database-Schema cannot be changed and Hibernate-version is fixed to 3.5</p>
  
  <p>I would also be happy if you tell me, that it is not possible</p>