Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Relationship and hibernate mapping

 
mohamed zafer
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi There,

Please help me on how to create the tables for the below scenario and the Hibernate mapping.

I have the below properties that can take values Yes or No,

Married ..? Yes/No
Employed...? Yes/No
US Citizen ..? Yes/No


I have an object called "Person", So when ever a new Person is created, I have to get and store the values of the above properties for
that person. I cannot add them as columns to the Person table as there can be dozens of these and also can be dynamically added.
So for each person, we have to create new rows with all the above properties and store their values.
This may be simple, but I just don't get how to do this...

Any help will be appreciated.

Thanks
Zafer mohamed
 
Mohd. Yakub
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Buddy Chap,
" I cannot add them as columns to the Person table as there can be dozens of these and also can be dynamically added. "


Now we can add as many properties as we want just with the addition single field in People table.
------------------------
Csae 2: If addition of field in People is not possible for u,then store it in a property file and retrive it contents on demands.

Cheers,
yakub

[ December 07, 2005: Message edited by: Mohd. Yakub ]

[ December 08, 2005: Message edited by: Mohd. Yakub ]

[ December 08, 2005: Message edited by: Mohd. Yakub ]
[ December 08, 2005: Message edited by: Mohd. Yakub ]
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you want to store multiple values in the same field, am I right? In which case, this means your ER model is not normalized properly since all values are not automic. This is asking for trouble, since not only are the values of each propery mutable, so are the property names themselves.

I'd model all these columns with three possible values "yes", "no", and "unknown". Then you can map them accordingly and default them all to unknown, unless otherwise set.
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you have dynamic field names, I'd be more inclined to create a separate table:



Then in your code, maintain a list of these for each Person.
[ December 08, 2005: Message edited by: Joel McNary ]
 
mohamed zafer
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Everybody.

I am planning to implement the way Joel has suggested.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic