Hi,
I have a strange problem for defineing one-to-many or many-to-many relationships with below tables and their relationships.
Table_A has composite keys with COLUMN_1 and LOC. Table_B has COLUMN_6 and LOC. When I try to map TableA_B as many-to-many, Hibernate not allowing me to use LOC twice for key declarations. I have composite PKs in all tables and LOC is one of compound PKs. Hibernate rejecting me to declare LOC twice in mapping file. If I have not used, it says we have to declare same number of Primary keys as compound primary keys.
Please advice me to come out from this problem.
Table_A Table_B Table_A_B
----------------------------------------------------------------
COLUMN_1 (PK) COLUMN_6 (PK) COLUMN_1 (PK)
LOC (PK) LOC (PK) COLUMN_6 (PK)
COLUMN_3 COLUMN_7 LOC (PK)
COLUMN_4 COLUMN_8
class TableA {
public String column1;
public String loc;
public String column3;
public String column4;
}
class TableB {
public String column6;
public String loc;
public String column7;
public String column8;
}
<hibernate-mapping>
<class name="TableA" table="TABLE_A">
<composite-id >
<key-property name="column1" column="COLUMN_1" />
<key-property name="loc" column="loc" />
</composite-id>
</class>
<class name="TableB" table="TABLE_B">
<composite-id >
<key-property name="column6" column="COLUMN_6" />
<key-property name="loc" column="loc" />
</composite-id>
</class>
thanks,
Seshagiri T.V.
|