I am trying to add a unique multi-column constraint on a collection of components. Usually, I would achieve this by using unique-key="xyz" on the properties in question. However, in this (probably not so) special case, I need the constraint to include the collection key (i.e. I need the components to be "unique per parent entity").
In the example below, I want to create a unique index on the COMPANY_PI table containing (company_id, year, branchId). Unfortunately, there is no
unique-key attribute on the
<key /> tag. Is there any way to achieve this through the hibernate mapping, other than using a
<database-object /> with custom DDL?
Any ideas or alternative approaches?
Thanks,
Michael
Code:
<class name="Company" table="COMPANY">
....
<set name="performanceIndicators" table="COMPANY_PI">
<key column="company_id" /> <!-- would like to use unique-key="abc" here -->
<composite-element class="PerformanceIndicators">
<property name="year" not-null="false" /> <!-- would like to use unique-key="abc" here -->
<property name="branchId" not-null="false" column="branch_id" /> <!-- would like to use unique-key="abc" here -->
<property name="..." not-null="false" />
</composite-element>
</set>
</class>
Hibernate version:
3.2.6