• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate Mapping & POJO Inheritance & Composition

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ranchers,

I'm new to hibernate and could do with some advice. I've done lots of reading and have got started....so far so good

However, despite reading this excellent link http://www.xylax.net/hibernate/index.html and others, i'm still a little unsure on how to map pojo's that may have inheritance or composition.

OK as an example lets imagine database tables:

Product(id, other product stuff)
TyreProduct(id, tyreWidth, tyreRim, other tyre product stuff)
BeerProduct(id, other beer specific product stuff)

So id is the primary key of product and tyreproduct or beer product have a one-to-one relationship (so the same pk).

My basic POJO may look like:





So my question is...is the class design ok and how would one tackle the mapping? I've had a play but don't seem to quite get things correct at the moment. I'm thinking that i need to use "one table per concrete class". Does that sound the best way? And if so how would my mapping look?

Thats my first question.

My second question is concerning composition. Lets imagine i have a class called TyreSize that records all the details required for a tyre size. So the class may look like:



With this new TyreSize object i could therefore remove the width and other tyre size specifics so my TyreProduct class could look like:



So is the use of the TyreSize object inside TyreProduct ok...and how would i map that?


I feel greedy asking two questions like this....but any help to get me on my way would be greatly appreciated. I think if i could see something in action for the above a lot of the reading i have done already would probably fall into place.

Cheers
 
Marcus Hathaway
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok i've found a good article and solution for my inheritance questions that other learners may find useful:

http://www.developer.com/open/article.php/10930_3559931_5

I'm still looking for inspiration on the composition issue if anyone has any suggestions?

So to summarise a database table:

TyreProduct(width, rim, aspect, speed, tyreCategory, //other tyre stuff)

In java i already have a class that can represent a TyreSize (so the width, rim, aspect, speed parts).

Therefore in the POJO TyreProduct instead of having to detail width, rim, aspect i can just have an object TyreSize. How can i populate that TyreSize in my mappings?

Thanks for any suggestions
 
Marcus Hathaway
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok i should of waited before posting but i found an answer to my other question here:

http://www.hibernate.org/hib_docs/reference/en/html/components.html#components-dependentobjects
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad we could help.

Mark
reply
    Bookmark Topic Watch Topic
  • New Topic