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 mapping parent child relationship Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "mapping parent child relationship" Watch "mapping parent child relationship" New topic

mapping parent child relationship

Raaj Aaryan

Joined: Feb 07, 2008
Posts: 4

I have just started using Hibernate and this forum has helped me in learning many issues on the run. However I am stuck up with one issue.

I have been searching around for a discussion on this issue but havent found anything yet (maybe my searched keywords were not optimum enough)

well I have a table which has a field referring to another field in the same table. For example

Create table emp (
emp_id int,
emp_name varchar(20),
emp_manager int

emp_id is the primary field here and the emp_manager is a foreign key refering to emp_id.

In my table.hbm.xml file how should I map this association such that on deleting any emp_id which appears the emp_manager the child fields should also get deleted.

any hints will be appreciated.

Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

The thing is, this is really a self-referential mapping, not really inheritance, right? The manager is also an employee, so the manager is a row in the employee table, right?

-Cameron McKenzie
Raaj Aaryan

Joined: Feb 07, 2008
Posts: 4
yes you are right, my mistake in word usage. its a recursive relationship .... any hints on the manner in which the mapping file should reflect this relation ?
I agree. Here's the link:
subject: mapping parent child relationship
It's not a secret anymore!