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
|
|