blob: a3e975a511dbd461fbe406ad1f582c53546e31df [file] [log] [blame]
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 (&quot;To Dep PK&quot; 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 (&quot;Table/View&quot; for subclasses is still &quot;BOOK&quot;). The only difference is that subclass-specific attributes are mapped as &quot;flattened attributes&quot;:</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 &quot;vertical&quot; inheritance.</P></BLOCKQUOTE>