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

Use Hibernate to Map one class in Java

 
Lozza Luton
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

Given the following database structure



Is it possible to map using hibernate some form of select so that I can have a pojo which looks something like below;



I am having real difficulty with this, and to top it all off there is another constraint. My BusinessCard, SocialCard, PersonalCard pojos all extend an abstract class Card which has a firstname last name and email address. This data is stored in the database in the PersonalInformation table

Thanks for your time
 
Winston Gutkowski
Bartender
Pie
Posts: 10571
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lozza Luton wrote:I am having real difficulty with this, and to top it all off there is another constraint. My BusinessCard, SocialCard, PersonalCard pojos all extend an abstract class Card which has a firstname last name and email address. This data is stored in the database in the PersonalInformation table

Seems to me that you're confusing database structure with Java structure. The Java POJOs that get created via Hibernate are "data access" objects, which may or may not convert directly to business objects as used in your application.

The conversion of one to the other seems pretty straightforward to me: A BusinessCard (and I'm not sure that it's the right name) as returned by your table can be converted to a proper "Card" by querying the PersonalInfo table with a matching userid.
However, that then begs the question: Why are Users and PersonalInfo separate? You may have reasons, but I can't see anything that leaps out at me from your structure diagram.

Winston
 
Lozza Luton
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Winston

Thank you for your reply. It is very much appreciated - I will begin the refactoring process now, my only reason for the separation of personal details was to try and isolate as much data in to functional tables as possible by grouping sets. It seemed as though a user table should have reference to some persona details rather than store them - if you catch my drift?

Thanks again
 
Winston Gutkowski
Bartender
Pie
Posts: 10571
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lozza Luton wrote:my only reason for the separation of personal details was to try and isolate as much data in to functional tables as possible by grouping sets. It seemed as though a user table should have reference to some persona details rather than store them - if you catch my drift?

Sure, so don't just blindly go slapping them together. It's your data, so you're the best person to decide what it should look like.

The best question to ask yourself is this: When you create a "user", are you always going to create a PersonalInfo row?
If the answer is "no" then they probably do need to be separate, because the relationship is optional.
If the answer is "yes", the next question to ask is: Will you create exactly ONE PersonalInfo row?
If the answer is "no" then they definitely need to be separate, because there is a 1:many relationship between Users and PersonalInfo.
If the answer is "yes", then you probably don't need PersonalInfo.

HIH

Winston
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic