title: Issue: Table per sub class using discriminator
body: <p><strong>Short Summary of Problem</strong></p>
  
  <p><strong>Hibernate is assuming that whenever someone is using subclass all the columns should be created in the top root of the class hierarchy irrespective of what table name has been provided.</strong> Can someone please explain the reasoning behind it and if there is way to bypass this code and somehow avoid invoice_id getting created in transaction table???</p>
  
  <p><strong>Details</strong></p>
  
  <p>I have a very deep class hierarchy in my domain model and want to use discriminator tag to support inheritance.</p>
  
  <p>Initially i mapped my classes using join-subclass, however the tables involved have hundreds of thousands of records and it is turning out to be a performance bottleneck. So in essence i want to flatten my table structure without touching the domain and that's why we moved on to discriminator tag.</p>
  
  <p>My hibernate mappings looks like(have deleted the extra column for sake of simplicity)</p>
  
  <p><strong>Transaction</strong> mapping</p>
  
  <pre><code>&lt;class name="Transaction" table="transaction" abstract="true"&gt;
     ...
      &lt;discriminator column="transaction_type" type="string"/&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p><strong>CashBasedTrsansaction</strong> mapping</p>
  
  <pre><code>&lt;subclass name="CashBasedTransaction" extends="Transaction" discriminator-value="CASH"&gt;
      &lt;join table="cash_based_transaction"&gt;
          &lt;key column="id" /&gt;
      &lt;/join&gt;
      &lt;subclass discriminator-value="BILLING" name="BillingTransaction"&gt;
          &lt;join table="billing_transaction"&gt;
              &lt;key column="id" /&gt;
              &lt;many-to-one name="invoice" column="invoice_id" cascade="all" access="field" lazy="false"&gt;
              &lt;/many-to-one&gt;
          &lt;/join&gt;
          &lt;subclass name="ChildBillingTransaction" discriminator-value="UPT"&gt;
              &lt;join table="billing_transaction"&gt;
                  &lt;key column="id" /&gt;
                  ...
              &lt;/join&gt;
          &lt;/subclass&gt;
          &lt;subclass abstract="true" name="AnotherChildOfBillingTransaction" discriminator-value="LPT"&gt;
               &lt;subclass name="SuperChildOfBillingTransaction" discriminator-value="OCLPT"&gt;
                   &lt;join table="billing_transaction"&gt;
                       &lt;key column="id" /&gt;
                       ...
                   &lt;/join&gt;
               &lt;/subclass&gt;
               &lt;subclass name="AnoherSuperChildOfBillingTransaction" discriminator-value="SLPT"&gt;
                   &lt;join table="billing_transaction"&gt;
                       &lt;key column="id" /&gt;
                       ...
                   &lt;/join&gt;
               &lt;/subclass&gt;
           &lt;/subclass&gt;&lt;!--End Of AnotherChildOfBillingTransaction--&gt;
       &lt;/subclass&gt;&lt;!--End Of BillingTransaction--&gt;
  &lt;/subclass&gt;&lt;!--End Of CashBasedTransaction--&gt;
  </code></pre>
  
  <p><strong>Invoice</strong> mapping</p>
  
  <pre><code>&lt;class name="Invoice" table="invoice"&gt;
      ...
      &lt;bag name="billingTransactions" access="field" cascade="all" inverse="true" table="billing_transaction"&gt;
          &lt;key column="invoice_id" /&gt;
          &lt;one-to-many class="BillingTransaction" /&gt;
      &lt;/bag&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p><strong>What i want to achieve</strong> : I want to flatten out table structure after billing_transaction. In other words i want to have only three tables in the database</p>
  
  <ul>
  <li>transaction</li>
  <li>cash_based_transaction</li>
  <li>billing_transaction(this table should hold all the columns after flattening out all the subclasses)</li>
  </ul>
  
  <p>P.S : Please note that i want to flatten out table structure not from the aggregate root(read transaction) but somewhere down the line in my class hierarchy, billing_transaction in this case.</p>
  
  <p><strong>Problem</strong> : Hibernate is creating a column "invoice_id" in transaction table(this is wrong) as well as in billing_transaction(this is correct). On further debugging i found some interesting results and need some feedback/advice.</p>
  
  <ul>
  <li><p>Hibernate creates a column invoice_id in billing_transaction which is what i want. </p></li>
  <li><p>Hibernate also creates another column with same name i.e. invoice_id in Transaction table which is not what i want. </p></li>
  </ul>
  
  <p>Now this is frustrating. Even though i have mentioned the table name(Billing_Transaction) in invoice.hbm and have set inverse="true" yet hibernate goes ahead and create a column invoice_id in transaction table even though there is already one in Billing_Transaction. I was expecting that since i am giving it the table name hibernate should take that name and check if billing_transaction has invoice_id or not... Instead hibernate is doing exactly opposite. It is completely ignoring the table name that i have provided and reaching out to the most super class i.e. Transaction. There it creates invoice_id column when it finds out that no such column exists. As a result i have two invoice_id column sitting in my tables. One in billing_transaction where i want it to be and another in transaction table where i don't want it to be.</p>
  
  <p>I have found out the code which is causing it. In org.hibernate.mapping.Subclass table is identified using the below given code</p>
  
  <pre><code>public Property getIdentifierProperty() {
    return getSuperclass().getIdentifierProperty();
  </code></pre>
  
  <p>}</p>
  
  <p>In other words <strong>hibernate is assuming that whenever someone is using subclass all the columns should be create in the top root of the class hierarchy irrespective of what table name has been provided.</strong> Can someone please explain the reasoning behind it and if there is way to bypass this code and somehow avoid invoice_id getting created in transaction table???</p>