cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Cayenne Documentation > Modeling Single Table Inheritance
Date Tue, 08 Jun 2010 21:02:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/9/1/_/styles/combined.css?spaceKey=CAYDOC&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAYDOC/Modeling+Single+Table+Inheritance">Modeling
Single Table Inheritance</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~andrus">Andrus
Adamchik</a>
    </h4>
        <br/>
                         <h4>Changes (0)</h4>
                                 
    
<div id="page-diffs">
            <table class="diff" cellpadding="0" cellspacing="0">
            <tr><td class="diff-snipped" >...<br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="ModelingSingleTableInheritance-ModelingSingleTableInheritance"></a>Modeling
Single Table Inheritance</h2>

<p>In a single table inheritance mapping all classes in the hierarchy are mapped to
the same base table. One or more columns in the base table are usually assumed to be "class
designator columns". Their values determine what object class to use when a fetched row is
converted to a persistent object. </p>

<h3><a name="ModelingSingleTableInheritance-CreatingObjEntityHierarchy"></a>Creating
ObjEntity Hierarchy</h3>

<p>Consider the following class hierarchy that we want to map to a PERSON table:</p>

<p><span class="image-wrap" style=""><img src="/confluence/download/attachments/10528/inheritance-diagram.jpg?version=1&amp;modificationDate=1140394374000"
style="border: 0px solid black" /></span></p>

<p>For each of the four Java classes one may create individual ObjEntities, however
only AbstractPerson entity would map directly to the underlying "PERSON" DbEntity. For the
rest instead of selecting a value from the "Table/View" dropdown, a corresponding "super entity"
from the "Inheritance" dropdown should be selected. Note that when an entity inherits from
another entity, a list of inherited attributes and relationships shows up as read only information
under the corresponding tabs.</p>

<h4><a name="ModelingSingleTableInheritance-DefiningClassQualifier"></a>Defining
Class Qualifier</h4>

<p>Afer creating entity inheritance tree, it is important to configure how the entities
differ from each other, so that later when the data is fetched, Cayenne would know which class
to instantiate. This is achieved by using entity qualifiers described earlier. Usually all
entities in the hierarchy, except for the root, require such qualifier. It should be created
in such a way that it completely defines a given entity without considering any subclasses
or superclasses. In the example above, if the possible values of the class designator column
are "EMPLOYEE", "MANAGER", "CUSTOMER", the following qualifiers might be used:</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'>ObjEntity</th>
<th class='confluenceTh'>Qualifier</th>
<th class='confluenceTh'>Final Qualifier Generated by Cayenne for SelectQuery</th>
</tr>
<tr>
<td class='confluenceTd'>AbstractPerson</td>
<td class='confluenceTd'>none</td>
<td class='confluenceTd'>none</td>
</tr>
<tr>
<td class='confluenceTd'>CustomerContact</td>
<td class='confluenceTd'>personType = 'CUSTOMER'</td>
<td class='confluenceTd'>personType = 'CUSTOMER'</td>
</tr>
<tr>
<td class='confluenceTd'>Employee</td>
<td class='confluenceTd'>personType = 'EMPLOYEE'</td>
<td class='confluenceTd'>personType = 'EMPLOYEE' or personType = 'MANAGER'</td>
</tr>
<tr>
<td class='confluenceTd'>Manager</td>
<td class='confluenceTd'>personType = 'MANAGER'</td>
<td class='confluenceTd'>personType = 'MANAGER'</td>
</tr>
</tbody></table>
</div>


<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td><b>Qualifiers Note</b><br
/>Qualifiers are not inherited! When defining qualifiers for inheritance purposes keep
in mind that the actual qualifier built by Cayenne will include the qualifier of a root entity
and qualifiers of all its known subentities joined using "or" operator, as shown in the above
example.</td></tr></table></div>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CAYDOC/Modeling+Single+Table+Inheritance">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=10528&revisedVersion=4&originalVersion=3">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAYDOC/Modeling+Single+Table+Inheritance?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message