Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Database Inheritance in Hibernate

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how Aggregation and specialization of database concept can be applied through
hibernate pojo class.

is it the pojo classes inheritance.....?

is there other way of achieving this....?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


how Aggregation and specialization of database concept can be applied through
hibernate pojo class


I'm not sure I follow what you are asking. Plain Old Java Objects achieve these in exactly the same way as any other object, the presence of Hibernate doesn't make them special.

Or am I misunderstanding your question?
 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rajesh Giriyappa:
...
is it the pojo classes inheritance.....?
....


YES
 
Rajesh Giriyappa
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Say for Simple Examples i have animal and dog hierarchy,

in which the dog inherits the animal class.

i can't see animal and dog as two seperate tables.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well Hibernate does suggest a pattern called "table per class hierarchy" which uses a discriminator column to tell Hibernate which type or object a row represents. Have a look in the docs, they cover this.

In my opinion, its an anti-pattern. Fine, it fixes what would be a slightly odd bit of OO modelling, but only by introducing poor modelling in your ER model (you have to introduce nullable properties for data that should never be null for example). My experience of database backed applications is that the data model is key, so don't weaken it lightly.
 
author and cow tipper
Posts: 5006
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at this class hierarchy:



Using a single class inheritance mapping strategy, you'd have a talbe that looks like this:



You'd get a database that looks something like this, after a single instance of each class was created:



Alternatively, a joined table inheritance mapping would generate tables that look like this:



And a single table per class mapping strategy would give you tables that looked like this:



Sorry about posting such big images. I just think that this visually helps you see how mapping strategies differ in how the data is managed.

These images were taken from this tutorial on Inheritance Mapping with Hibernate and JPA Annotations:

Mapping Inheritance with Hibernate and JPA - An Example

-Cameron McKenzie
 
Amateurs built google. Professionals built the titanic. We can't find the guy that built this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic