Extended Entity-Relationship Model to tables (subclasses)

一世执手 提交于 2019-12-06 03:09:17

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!