-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: one to many bi-directional mapping
PostPosted: Tue May 30, 2006 4:40 am 
Newbie

Joined: Tue May 30, 2006 1:13 am
Posts: 1
Question 1: How to map complex object in Hibernate

Following is the scenario; need to persist the data of Parent object into PARENT Table and data of Child object into CHILD Table.

PARENT & CHILD has one to many & bi-directional relation. Parent has a set of children & child can also know about their parent.

class Parent {
int parent_Id;
String parentName;
int parentAge;
private Member member
}

class Member {
private Set child; // set of Child object.
}

class Child {
int child_Id;
String childName;
int chidAge;
Parent parent;
}

Tables:
Table PARENT
-------------------
PARENT_ID DECIMAL (10) NOT NULL (PK)
PARENT_NAME VARCHAR (40) NOT NULL
PARENT_AGE SMALLINT NOT NULL

Table CHILD
----------------
PARENT_ID DECIMAL (10) NOT NULL (FK)
CHILD_ID DECIMAL (2) NOT NULL (PK)
CHILD_NAME VARCHAR (40) NOT NULL
CHILD_AGE SMALLINT NOT NULL

Note:
PARENT_ID is the primary key for the PARENT table
PARENT_ID & CHILD_ID is the composite key for the CHILD table.

Sample data in the tables
-----------------------------
PARENT
PARENT_ID PARENT_NAME PARENT_AGE
10001 Smith 46
10002 Mathew 50

CHILD
PARENT_ID CHILD_ID CHILD_NAME CHILD_AGE
10001 1 John 18
10001 2 Cathy 16
10001 3 Harry 12
10002 1 Mike 22
10002 2 Sania 15

Please help me to write the hbm file to map the object to the corresponding table by Hibernate framework.

I am successfully able to map the Parent & Child if Parent has a field as a set of Child.

But in the above case "Member object" comes into the picture, where Member has a composition relation with Parent & Member has a set of Child object.

Thanks in advance to provide the solution for mapping above situation.

Thanks & Regards
Ausaf Ahmad
9895026149


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 30, 2006 5:09 am 
Newbie

Joined: Mon May 29, 2006 12:57 am
Posts: 11
Location: india
Hi,

I don't understand why you would like to have the member class if there is only the child set within it. You can have it directly within the parent class.

Any comments????


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.