GeeCON Prague 2014*
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
Author

mapping parent child relationship

Raaj Aaryan
Greenhorn

Joined: Feb 07, 2008
Posts: 4
Hi,

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.

thanks
Raaj
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

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
Greenhorn

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 ?
 
GeeCON Prague 2014
 
subject: mapping parent child relationship