• 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

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: 5009
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
 
I found a beautiful pie. And a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic