Is there a way to add to the default primary key definition of a map using a 'unique-key' tag or something of that nature? By default, hibernate uses the 'key' and 'map-key' tags to create the primary key index. I would like to include one additional field in that primary key.
For example, I have a class called EAccount that can be used for either Email or IMPP. I have another 'Person' class that has maps of both email and impp accounts (e.g. Map emailAccounts = new HashMap()). I would like to use the same database table to store both email and impp accounts. My mappings are as follows:
Code:
<class name="Person" table="person">
...
<map name="emailAccounts" table="eaccount">
<key column="person_id"/>
<map-key column="type" type="string"/>
<composite-element class="EAccount">
<property name="address"/>
<property name="accountType" column="account_type" type="EAccountUserType"/>
</composite-element>
</map>
<map name="imppAccounts" table="eaccount">
<key column="person_id"/>
<map-key column="type" type="string"/>
<composite-element class="EAccount">
<property name="address"/>
<property name="accountType" column="account_type" type="EAccountUserType"/>
</composite-element>
</map>
...
</class>
Is there a way to specify that the 'accountType' property be included in the primary key?
I realize that it's a simple enough task to write the SQL creation script for that table myself but I would prefer to allow Hibernate to take care of that particular detail.
Code: