• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Parent-Child Confusion ....

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers,

Please refer the mapping and bean classes below.


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

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

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


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

</class>

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

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

</hibernate-mapping>




=============================================


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 session.save(employeeObject) assosiated Department Object also gets saved in Department table whereas this is not the case when I try session.save(department) as it only saves Department object.

Thanks & Regards
Maneesh Saxena






 
First, you drop a couch from the plane, THEN you surf it. Here, take this tiny ad with you:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic