title: Foreign key creation in one-to-one table-per-concrete-class structure
body: <p><strong>TL;DR</strong> How can I enforce the Hibernate schema creation to create a foreign key constraint in a table-per-concrete-class setup from <code>AbstractProperty.ownerId</code> to <code>Owner.ownerId</code> for the structure displayed below, without adding a <code>Owner</code> property to the <code>AbstractProperty</code>?</p>
  
  <p>I'm working on a project where I have the following class structure:</p>
  
  <p><img src="https://i.stack.imgur.com/MVG5U.png" alt="Class structure sample"></p>
  
  <p>The <code>Owner</code> has a one-to-one mapping to an <code>AbstractProperty</code>, which is extended by the <code>ConcreteProperty</code> class (and others like <code>AnotherProperty</code>, but that's not really relevant for the rest of this question).</p>
  
  <p>The <code>AbstractProperty</code> really has only one property, the <code>abstractPropertyId</code>. Therefor, we want to use the <a href="http://docs.jboss.org/hibernate/orm/4.2/manual/en-US/html_single/#inheritance-tableperconcrete" rel="nofollow noreferrer">table-per-concrete-class</a> structure, ending up with the tables <code>Owner</code>, <code>ConcreteProperty</code>, and tables for the other <code>AbstractProperty</code> extending classes (<code>AnotherProperty</code>).</p>
  
  <p>To this end, I created the following mapping for <code>Owner</code>:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
      "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"&gt;
  &lt;hibernate-mapping package="com.example"&gt;
      &lt;class name="Owner"&gt;
          &lt;id name="ownerId"&gt;
              &lt;generator class="identity"/&gt;
          &lt;/id&gt;
          &lt;property name="ownerProperty"/&gt;
          &lt;one-to-one name="abstractProperty"/&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>And for the <code>AbstractProperty</code>:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
      "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"&gt;
  &lt;hibernate-mapping package="com.example"&gt;
      &lt;class name="AbstractProperty" abstract="true"&gt;
          &lt;id name="ownerId"&gt;
              &lt;generator class="foreign"&gt;
                  &lt;param name="property"&gt;ownerId&lt;/param&gt;
              &lt;/generator&gt;
          &lt;/id&gt;
          &lt;union-subclass name="ConcreteProperty"&gt;
              &lt;property name="concreteProperty"/&gt;
          &lt;/union-subclass&gt;
          &lt;union-subclass name="AnotherProperty"&gt;
              &lt;property name="anotherProperty"/&gt;
          &lt;/union-subclass&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>This works.</p>
  
  <p>However, and here is my question, using this mapping and having Hibernate create the schema for me (<code>&lt;property name="hbm2ddl.auto"&gt;create&lt;/property&gt;</code>), it does not create a foreign key constraint from the <code>ConcreteProperty.ownerId</code> database field to the <code>Owner.ownerId</code> field. It does when I create the inverse constrained one-to-one field from the <code>AbstractProperty</code> to <code>Owner</code> using this mapping for <code>AbstractProperty</code> (where the <code>owner</code> field is of type <code>Owner</code> in the <code>AbstractProperty</code> java class):</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
      "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"&gt;
  &lt;hibernate-mapping package="com.example"&gt;
      &lt;class name="AbstractProperty" abstract="true"&gt;
          &lt;id name="ownerId"&gt;
              &lt;generator class="foreign"&gt;
                  &lt;param name="property"&gt;ownerId&lt;/param&gt;
              &lt;/generator&gt;
          &lt;/id&gt;
          &lt;one-to-one name="owner" constrained="true"/&gt;
          &lt;union-subclass name="ConcreteProperty"&gt;
              &lt;property name="concreteProperty"/&gt;
          &lt;/union-subclass&gt;
          &lt;union-subclass name="AnotherProperty"&gt;
              &lt;property name="anotherProperty"/&gt;
          &lt;/union-subclass&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>How can I enforce the creation of a foreign key from <code>AbstractProperty.ownerId</code> to <code>Owner.ownerId</code> without this <code>Owner</code> field in my <code>AbstractProperty</code>?</p>