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

Hibernate's Inheritance strategies

 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

My doubt is related to Table per class hierarchy.
refering to hibernate documentation:---
Exactly one table is required for the whole inheritance.
There is one big limitation of this mapping strategy: columns declared by the subclasses may not have NOT NULL constraints

why we can not declare NOT NULL constraints for the columns mapped to sub-class property ?
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My understanding is that because some of your sub classes won't have a field that maps to a particular column. Hibernate needs to be able to put in a null to represent that fact.
 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand this explaination. please give me a proper reason as I am an novice to Hibernate...
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, that is a pretty decent reason.

You have one table that models a range of types, all with one common ancestor. These types will have different properties that need persisting but can only be persisted for that specific child type. So these properties need to be supported by nullable fields in the database table, and hence you end up with possibly mandatory properties in your Object model that are mapped to nullable fields in your data model.

I take the view that the data model is king, since you have no view of the variety of applications that may connect to it an manipulate the data. So I'd not recommend the table per class hierarchy pattern.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic