Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
shyam shridhar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
shyam shridhar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please post the table structures(Sample) involved, so that I can try to make a mapping for you.
 
shyam shridhar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please suggest, Is it possible or not? any other alternative to do the same.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic