| Title: Modeling Vertical Inheritance |
| |
| <H2><A name="ModelingVerticalInheritance-ModelingVerticalInheritance"></A>Modeling Vertical Inheritance</H2> |
| |
| <P>Continuing with the example used for <A href="modeling-single-table-inheritance.html" title="Modeling Single Table Inheritance">single table mapping</A>, let's re-map it as vertical inheritance.</P> |
| |
| <P><SPAN class="image-wrap" style=""><IMG src="modeling-vertical-inheritance.data/vertical-inheritance.png" style="border: 0px solid black"></SPAN></P> |
| |
| <P>Note that in Cayenne <B>vertical</B> is essentially <B>single table with flattened attributes in subclasses</B>. We'll demonstrate this below.</P> |
| |
| <P>We need to start by mapping all 3 tables, and creating 1..1 relationship between BOOK and subclass tables ("To Dep PK" must be checked on BOOK side of relationships).</P> |
| |
| <P>On the ObjEntity end, there is no difference in mapping qualifier (it is needed), superclass, root table ("Table/View" for subclasses is still "BOOK"). The only difference is that subclass-specific attributes are mapped as "flattened attributes":</P> |
| |
| <P><SPAN class="image-wrap" style=""><IMG src="modeling-vertical-inheritance.data/flattened_attribute.png" style="border: 0px solid black"></SPAN></P> |
| |
| <BLOCKQUOTE><P>Note that flattened attributes can be used with or without inheritance, however in combination with single-table inheritance mapping, they give us "vertical" inheritance.</P></BLOCKQUOTE> |