The entity i want is this:
Code:
class ExternalAccounts {
private String externalAccountType; // part of key
private String externalAccountId; // part of key
private Set<Integer> accountIds; // collection of account ids
}
My table "external_account" looks like:
external_account_type(string), external_account_id(string), account_id(integer)
Clearly i can have many different accounts for a particular "key" (ie, externalAccountType + externalAccountId).
The mapping i tried:
Code:
<class name="ExternalAccounts" table="external_account">
<composite-id>
<key-property name="externalAccountType" column="external_account_type" />
<key-property name="externalAccountId" column="external_account_id" />
<composite-id>
<set name="accountIds" table="external_account">
<key>
<column name="external_account_type"/>
<column name="external_account_id"/>
</key>
<element column="account_id" type="integer"/>
</set>
</class>
But i get a "multiple entries with the same key" error when i try to load an ExternalAccounts object. I of course just set the externalAccountType and externalAccountId and pass that in to the "load" method. The error does make sense, and i can "fix" this by using a 2nd table; but i'd rather not.
Is there a mapping that will get me what i want?
Thanks.