File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Please suggest on this Mapping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Please suggest on this Mapping" Watch "Please suggest on this Mapping" New topic

Please suggest on this Mapping

Xavier George
Ranch Hand

Joined: Jul 29, 2005
Posts: 39
Is there something wrong in this mapping. The parent is saved but Child failed to Save.

This is a simple one-to-many mapping of Dept(one) and Emp (Many) with composite PK and no FK.
I am using composite PK class. Do we really need the existence of FK for mapping ?


<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"

<hibernate-mapping package="hello">
<class name="Dept" table="DEPT">

<composite-id name="key" class="DeptKey">
<key-property name="empno" type="string"/>
<key-property name="deptno" type="string"/>

<property name="deptname" type="string"/>

<set name="emp" table="emp" inverse="true" cascade="all" lazy="false">
<column name="EMPNO" />
<column name="DEPTNO" />
<one-to-many class="Emp" />



<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"

<hibernate-mapping package="hello">
<class name="Emp" table="EMP">

<composite-id name="key" class="EmpKey">
<key-property name="empno" type="string"/>
<key-property name="deptno" type="string"/>

<property name="sal" type="string"/>
<property name="loc" type="string"/>

<many-to-one name="dept" insert="false" update="false" cascade="save-update" class="Dept"/>
<column name ="empno"/>
<column name="deptno"/>


In many-to-one mapping I had to set insert and update to false as Hibernate is giving following error -

*** Repeated column in mapping for entity: EMP column: EMPNO (should be mapped with insert="false" update="false")

Persistence class and Client is here -
Complete Code
Ghulam Rashid
Ranch Hand

Joined: Jan 14, 2002
Posts: 278
Its look okay to me. May be you need to look into the client program, how you are persisting it.
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 661

can't we use something like this,

[ August 10, 2006: Message edited by: Arun Kumarr ]

If you are not laughing at yourself, then you just didn't get the joke.
I agree. Here's the link:
subject: Please suggest on this Mapping
It's not a secret anymore!