My mapping does not worry about defining PK or composite PK.
Code:
<hibernate-mapping>
<class entity-name="ITEM_ITEM_PC" table="ITEM_ITEM_PC">
<id name="ID" type="long" column="ID" unsaved-value="0">
<generator class="sequence">
<param name="sequence">dyn_seq_28</param>
</generator>
</id>
<property name="USER_DOC_ID" type="string" column="USER_DOC_ID" not-null="true" unique-key="composite_unique" />
<property name="IS_ACTIVE" type="boolean" column="IS_ACTIVE" not-null="true" />
<property name="rtd_version" type="integer" column="rtd_version" not-null="true" unique-key="composite_unique" />
<property name="TEMPLATE_NAME" column="TEMPLATE_NAME" type="string" />
<property name="ORDINAL" type="integer" column="ORDINAL" not-null="false" />
<property name="lineId" type="string" column="lineId" not-null="false" length="32" unique-key="composite_unique" />
</class>
</hibernate-mapping>
In above mapping i have defined unique-key for "USER_DOC_ID", "rtd_version" and "lineId" which makes combination
("USER_DOC_ID" + "rtd_version" + "lineId") unique. But i want uniqueness on
("USER_DOC_ID" + "rtd_version") and
("USER_DOC_ID" + "lineId").my table script is,
Code:
CREATE TABLE "ITEM_ITEM_PC"
( "ID" NUMBER(19,0) NOT NULL ENABLE,
"TEMPLATE_NAME" VARCHAR2(255 CHAR) NOT NULL ENABLE,
"USER_DOC_ID" VARCHAR2(255 CHAR) NOT NULL ENABLE,
"IS_ACTIVE" NUMBER(1,0) NOT NULL ENABLE,
"RTD_VERSION" NUMBER(10,0) NOT NULL ENABLE,
"ORDINAL" NUMBER(10,0),
"LINEID" VARCHAR2(32 CHAR),
PRIMARY KEY ("ID") ENABLE,
UNIQUE ("USER_DOC_ID", "RTD_VERSION", "LINEID") ENABLE,
)
And i can modify the constraint in script like
UNIQUE ("USER_DOC_ID", "RTD_VERSION")
UNIQUE ("USER_DOC_ID", "LINEID")
to make ("USER_DOC_ID" + "rtd_version") and ("USER_DOC_ID" + "lineId") unique.
.
So i want to define same constraint at hbm level. I hope the problem is clear.
Thanks,
Hari Prasad Alla.