3

In the EER model there are subclasses entities. I was wondering what's the way to implement that in a real SQL Table or if there is any guide that might help me out to understand how to implement entities subclasses into tables that would help. Thanks

dgilperez
  • 10,716
  • 8
  • 68
  • 96
Christopher Francisco
  • 15,672
  • 28
  • 94
  • 206

2 Answers2

5

Martin Fowler's book Patterns of Enterprise Application Architecture covers solutions for subclassing tables:

These correspond to the options in the answer from @spencer7593, without being tied to Java & Hibernate.

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
  • +1. This is a better answer than my answer. (No one likes to be tied to Hibernate, but the documentation is invaluable if you are tied to it.) – spencer7593 Jul 24 '13 at 19:37
3

The Hibernate documentation has discussion of the options available for representing inheritance hierarchies in a relational database. There are undoubtedly better tutorials, but the Hibernate ORM (love-it-or-hate-it) wrestled with this problem.

Because there is no single "best way" to represent an inheritance hierarchy, they support all the options:

  • table per class hierarchy - basically one table, with all the attributes from all the subclasses. lots of columns will likely be null on lots of rows

  • table per subclass - one table for the superclass, and a separate table for each subclass

  • table per concrete subclass - separate table for each subclass (no table for superclass)

There's no single right answer. Each of these approaches benefits and drawbacks.

http://docs.jboss.org/hibernate/orm/3.3/reference/en-US/html/inheritance.html

spencer7593
  • 106,611
  • 15
  • 112
  • 140
  • +1 Yep, Hibernate is a concrete implementation of these patterns, and if the OP is using Java, it's very relevant. – Bill Karwin Jul 25 '13 at 00:20