I finally understand what Gavin was trying to explain to me. I should remove the "column" attribute from the "many-to-one" mapping. It took some time to beat through this so I am adding the final xml to this topic trail to help other lost souls. Thanks Gavin for your help and patients :).
The many side of the relation
note the "column" attribute has been removed
<hibernate-mapping>
<class name="com.pojo.Child" table="CHILD">
<id name="id" type="int" column="id">
<meta attribute="scope-set">protected</meta>
<generator class="native"/>
</id>
<many-to-one name="parent" class="com.pojo.Parent">
<column name="parent" index="ind" unique-key="unq"/>
</many-to-one>
<property name="col" type="int">
<column name="col" not-null="true" index="ind" unique-key="unq"/>
</property>
<property name="col2" type="int">
<column name="col2" not-null="true" index="ind" unique-key="unq"/>
</property>
</class>
</hibernate-mapping>
The one side of the relation
note the "column" attribute is defined here
<hibernate-mapping>
<class name="com.pojo.Parent" table="PARENT">
<id name="id" type="int" column="id">
<meta attribute="scope-set">protected</meta>
<generator class="native"/>
</id>
<set name="children" inverse="true" cascade="all-delete-orphan">
<key column="parent_id"/>
<one-to-many class="com.pojo.Child"/>
</set>
</class>
</hibernate-mapping>
SQL output
create table CHILD (
id integer generated by default as identity (start with 1),
parent integer,
col integer not null,
col2 integer not null,
parent_id integer,
unique (parent, col, col2)
)
create index ind on CHILD (parent, col, col2)
alter table CHILD add constraint FK3D1FCFCC4AB08AA foreign key (parent) references PARENT
|