I've got a Transaction parent class that reflects a "Transactions" table in our database. We then have child tables such as CreditCardPayments, CashPayments, CheckPayments, etc. We also have a table, "Transfers," that acts as a child class for two transactions. The Transfers table has "from_transaction_id" and "to_transaction_id" columns.
I tried to implement it as follows (with just the transfer applicable sections):
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Lib" namespace="Lib.Domain">
<class name="Lib.Domain.Transaction, Lib" table="Transactions">
<id name="Id" column="transaction_id">
<generator class="native" />
</id>
<property name="EnterDate" column="enter_date" generated="insert" />
<property name="Amount" column="amount" />
<property name="Type" column="transaction_type_id" />
<property name="Status" column="transaction_status_id" />
<many-to-one name="User" class="User" column="user_id" />
<!-- Define transfers -->
<joined-subclass name="TransferReceived" table="Transfers">
<key column="to_transaction_id" />
<property name="Comments" column="comments" length="500" />
<many-to-one name="FromTransaction" class="Transaction" column="from_transaction_id" cascade="all" />
</joined-subclass>
<joined-subclass name="TransferSent" table="Transfers">
<key column="from_transaction_id" />
<property name="Comments" column="comments" length="500" />
<many-to-one name="ToTransaction" class="Transaction" column="to_transaction_id" cascade="all" />
</joined-subclass>
</class>
</hibernate-mapping>
The issue I am running into is that the query it executes doesn't seem correct and it results in the error "Cannot instantiate abstract class or interface: Lib.Domain.Transaction." It joins on Transfers twice (as expected) on the same column (from_transaction_id -- not expected). It should join once on to_transaction_id and once on from_transaction_id. I can get it to read properly if I create a view for transfers sent and transfers received. But, of course, I then cannot persist the changes to the database. Any thoughts on if I am doing this wrong or what I need to do to get this to work?