views:

11

answers:

1

Ayende has a great example of using the <any> mapping here, which I am reposting as part of my question since comments are closed on that blog post. Given his original mapping:

<class name="Order" table="Orders">

    <id name="Id">
        <generator class="native"/>
    </id>

    <any name="Payment" id-type="System.Int64" meta-type="System.String" cascade="all">
        <meta-value value="CreditCard" class="CreditCardPayment"/>
        <meta-value value="Wire" class="WirePayment"/>
        <column name="PaymentType"/>
        <column name="PaymentId"/>
    </any>

</class>

<class name="CreditCardPayment" table="CreditCardPayments">
    <id name="Id">
        <generator class="native"/>
    </id>
    <property name="IsSuccessful"/>
    <property name="Amount"/>
    <property name="CardNumber"/>
</class>

<class name="WirePayment" table="WirePayments">
    <id name="Id">
        <generator class="native"/>
    </id>
    <property name="IsSuccessful"/>
    <property name="Amount"/>
    <property name="BankAccountNumber"/>
</class>

... how would I go about mapping a property named Order on the CreditCardPayment and WirePayment classes which would be the "flip side" of the association allowing traversal from these payments back up to the Order they are associated with?

The gotcha for me here is that CreditCardPayment and WirePayment can potentially have the same IDs since they are in different tables, so I need some way to tell NHibernate to take the PaymentType into consideration.

A: 

Bidirectional heterogeneous associations (i.e. <any>) are not supported by NHibernate.

I know this isn't what you wanted to hear, but that's it.

Diego Mijelshon