This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Parent-Child Confusion .... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Parent-Child Confusion ...." Watch "Parent-Child Confusion ...." New topic

Parent-Child Confusion ....

Maneessh saxena
Ranch Hand

Joined: Oct 03, 2006
Posts: 125
Hi Ranchers,

Please refer the mapping and bean classes below.

<class name="com.test.beans.Employee" table="Employee">

<id name="empId" column="id">
<generator class="foreign">
<param name="property">department</param>

<property name="name">
<column name="name" />

<one-to-one name="department" cascade="all"
class="com.test.beans.Department" constrained="true"></one-to-one>


<class name="com.test.beans.Department" table="Department">
<id name="Id" type="long" column="id" unsaved-value="0">
<generator class="increment" />

<property name="deptName" unique="true">
<column name="deptName" />



public class Department {
private long Id;
private String deptName;
.............................Gettr Setters.......


public class Employee {
private String name;
private long empId;
Department department;
.............................Gettr Setters.......


My Question is if Employee table is parent of Department as Employees compposes Department ? Or reverse is true i.e Department table is parent of Employee.

When I try assosiated Department Object also gets saved in Department table whereas this is not the case when I try as it only saves Department object.

Thanks & Regards
Maneesh Saxena

SCJP 1.4, SCWCD 1.5
jQuery in Action, 2nd edition
subject: Parent-Child Confusion ....
Similar Threads
hibernate 1:M relationships & cascade
Hibernate exception for one-to-one mapping
one to many mapping
Doubt in Mapping Associations
Mapping Error Hibernate