I have three classes/mappings and I have found that I am getting two params reversed on insert statements when using Hibernate. Here's the mappings
<!-- mapping 1 -->
<hibernate-mapping>
<!--
Created by Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="TableA"
table="TABLE_A"
>
<id
name="aId"
type="long"
column="A_ID"
>
<generator class="assigned" />
</id>
<set
name="tableBs"
lazy="false"
inverse="true"
cascade="all-delete-orphan"
>
<key>
<column name="A_ID" />
</key>
<one-to-many
class="TableB"
/>
</set>
</class>
</hibernate-mapping>
<! --- mapping 2 -->
<hibernate-mapping>
<!--
Created by Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="TableB"
table="TABLE_B"
>
<composite-id name="comp_id" class="TableBPK">
<key-property
name="extId"
column="EXT_ID"
type="int"
length="10"
/>
<!-- bi-directional many-to-one association to TableA -->
<key-many-to-one
name="tablea"
class="TableA"
>
<column name="A_ID" />
</key-many-to-one>
</composite-id>
<set
name="tableCs"
lazy="false"
inverse="true"
cascade="all-delete-orphan"
>
<key>
<column name="A_ID" />
<column name="EXT_ID" />
</key>
<one-to-many
class="TableC"
/>
</set>
</class>
</hibernate-mapping>
<!-- mapping 3 -->
<hibernate-mapping>
<!--
Created by Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="TableC"
table="TABLE_C"
>
<id
name="cId"
type="int"
column="C_ID"
>
<generator class="sequence">
<param name="sequence">c_id_seq</param>
</generator>
</id>
<many-to-one
name="tableB"
class="TableB"
not-null="true"
>
<column name="A_ID" />
<column name="EXT_ID" />
</many-to-one>
</class>
</hibernate-mapping>
<! -- End Mappings -- >
<!-- classes -->
class TableA
{
private Long aId;
private Set tableBs;
// getters, setters, constructors, and that's it
}
class TableB
{
private TableBPK comp_id;
private Set tableCs;
// getters, settters, constructor
}
class TableBPK
{
private int extId;
prvate TableA tableA;
// getters, setters, constructors
}
class TableC
{
private Integer cId;
private TableB tableB;
// getters, setters, constructor
}
All the mappings were generated by Middlegen and all the Java code was generated by hbm2java.
I had no problems with just Table A and Table B. When I added Table C and tried to save, I got a foreign key violation from the C->B relationship. I dropped the key constraint on C, and then the insert worked, but I realized that it had put the value for EXT_ID in A_ID, and the value for A_ID in EXT_ID. Hence the foreign key constraint. I thought that surely I had done something obviously wrong, causing these two values to be reversed, but I couldn't really see what would cause this. I tried reversing the order in the TableB mapping's set:key section, but to no avail. Any ideas what would cause these values to get placed incorrectly by inserts issued by Hibernate?