aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate mapping : Parent ->Child(Male or Female) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate mapping : Parent ->Child(Male or Female)" Watch "Hibernate mapping : Parent ->Child(Male or Female)" New topic
Author

Hibernate mapping : Parent ->Child(Male or Female)

shyam shridhar
Ranch Hand

Joined: Sep 15, 2006
Posts: 31
Hi all,

I'm facing problem to create mapping based on the following scenario.

Parent
----------------
Id -> long
name -> varchar

Child
-----------------
Id -> varchar
name -> varchar
parent_id -> long
gender -> short [1-for male, 2 for female]

Now from parent entity object want to get babyChildren [set/list] and boyChildren [set/list].

Please suggest How I could achieve my goal?

-shyam

Aneesh Vijendran
Ranch Hand

Joined: Jun 29, 2008
Posts: 125
Hi,
You'll have to use the One To Many Mapping. You can get the data as collection or Array.
Refer the hibernate docs for examples:

http://docs.jboss.org/hibernate/core/3.3/reference/en/html/collections.html

Cheers
Aneesh


Cheers
Aneesh
shyam shridhar
Ranch Hand

Joined: Sep 15, 2006
Posts: 31
Aneesh Vijendran wrote:Hi,
You'll have to use the One To Many Mapping. You can get the data as collection or Array.
Refer the hibernate docs for examples:

http://docs.jboss.org/hibernate/core/3.3/reference/en/html/collections.html

Cheers
Aneesh



Thanks Aneesh, but my case is slightly different.. I founded in hibernate doc following code




but I want something like as below



I don't know it possible with hibernate or not. Please suggest


Aneesh Vijendran
Ranch Hand

Joined: Jun 29, 2008
Posts: 125
Can you please post the table structures(Sample) involved, so that I can try to make a mapping for you.
shyam shridhar
Ranch Hand

Joined: Sep 15, 2006
Posts: 31
Aneesh Vijendran wrote:Can you please post the table structures(Sample) involved, so that I can try to make a mapping for you.


Thanks a lot Aneesh,
Actually I had put some wrong code in my previous post, now I have corrected see below. I apologies for wasting your time.



Please find the table structure below.

Parent Table
----------------
Id -> long
name -> varchar

Child Table
-----------------
Id -> long
name -> varchar
parent_id -> long
gender -> short [1-for male, 2 for female]


-s
shyam shridhar
Ranch Hand

Joined: Sep 15, 2006
Posts: 31
Please suggest, Is it possible or not? any other alternative to do the same.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate mapping : Parent ->Child(Male or Female)
 
Similar Threads
what changes should i made in save method in one-to-many relationships
How to insert a new child record only. One to Many Relation.
retrieving object hierarchy - many-to-one?
Hibernate Bidirectional Mapping Problem.
Hibernate 3.0 : Where am I going wrong?