Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:hibernate3.2.1.ga
Mapping documents:
Code:
<hibernate-mapping>
<class name="com.A" table="TABLE_A">
<id name="aId" type="java.lang.Long">
<column name="A_ID" precision="29" scale="0" />
<generator class="increment" />
</id>
......
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="com.B" table="TABLE_B">
<id name="bId" type="java.lang.Long">
<column name="B_ID" precision="29" scale="0" />
<generator class="increment" />
</id>
......
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="com.C" table="TABLE_C">
<id name="cId" type="java.lang.Long">
<column name="C_ID" precision="29" scale="0" />
<generator class="increment" />
</id>
<many-to-one name="a" class="com.A" fetch="select">
<column name="A_ID" precision="29" scale="0" not-null="true" unique-key="aAndBUnique"/>
</many-to-one>
<many-to-one name="b" class="com.B" fetch="select">
<column name="B_ID" precision="29" scale="0" not-null="true" unique-key="aAndBUnique"/>
</many-to-one>
......
</class>
</hibernate-mapping>
NAORA-00001: unique constraint (AANDBUnique) violatedOracle 9NANAProblems with Session and transaction handling? No
As you can see from the above mapping. The column A_ID and B_ID in class C are composite unique keys. They are primary keys for table A and B respectively.
But when I call
C c = new C();
c.setA(new A(1));
c.setB(new B(2));
saveOrUpdate(c);//Call 1
c.set(....);//update C
saveOrUpdate(c);//Call 2
Call 1 inserts in the value in the database, which is correct. But the Call2 instead of updating the row, tries to insert the row and hence violating the unique key constraint.
How should I map a table with composite unique key constraint?
Code:
Code: