Hibernate is great, but I can't come up with a way to accomplish the following: I need to join another table to get the keys for a set. We have three objects: an abstract Account class, a SimpleAccount, and an AggregateAccount. An AggregateAccount is exactly like a SimpleAccount, only it also contains a set of it's subaccounts. The database schema consists of two tables: Accounts, which contains all data for each account, and Aggregates, which maps aggregate accounts (in the Accounts table) to simple accounts (also in the Accounts table).
Here is my mapping file:
Code:
<class name="Account" table="Accounts" discriminator-value="0">
<id name="id" column="ID">
<generator class="identity"/>
</id>
<discriminator column="Aggregate" type="integer"/>
<property name="name"/>
<property name="shortName"/>
<subclass name="SimpleAccount" discriminator-value="0" />
<subclass name="AggregateAccount" discriminator-value="1">
<set name="subAccounts">
<key column="ID"/>
<one-to-many class="Account"/>
</set>
</subclass>
</class>
I need to be able to essentially join on the Aggregates table to get the Accounts that should be in the subAccounts set in the AggregateAccount subclass. Is there a way to use a key in another table as the collection key? Is there another straight-forward way of doing this?