cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [CONF] Apache Cayenne Documentation > CayenneModeler Flattened Relationships
Date Thu, 10 Sep 2009 23:24:00 GMT
    <base href="">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAYDOC&amp;forWysiwyg=true"
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="">CayenneModeler
Flattened Relationships</a></h2>
     <h4>Page <b>edited</b> by             <a href="">Ari
     add link
          <div id="versionComment" class="noteMacro" style="display:none; padding: 5px;">
     add link<br />
     <div class="notificationGreySide">
         <h3><a name="CayenneModelerFlattenedRelationships-FlattenedRelationships"></a>Flattened

<p>ObjRelationships that map to more than a single DbRelationship are called "flattened".</p>

<p>The most common case for using flattened relationships is modeling many-to-many relationships
with a join table. E.g. ARTIST DbEntity has to-many relationship to ARTIST_EXHIBIT; ARTIST_EXHIBIT
in turn has a to-one relationship to EXHIBIT DbEntity. We can create a single ObjRelationship
from Artist ObjEntity to Exhibit ObjEntity that spawns two DbRelationships. This will be a
to-many relationship. Lets say it is called "exhibitArray". Generated class file for Artist
would contain a getExhibitArray() method returning a list of Exhibits for a given artist instance.
An obvious advantage of having a flattened relationship in this case is to avoid mapping a
join table as an object, meaningless in the context of the object model.</p>

<p>Flattened relationships work across any combination of to-one and to-many DbRelationships.
If all the relationships are to-one, then the resulting flattened relationship is also to-one.
If there is at least one to-many, the result is to-many as well.</p>
<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>Read-Only Note</b><br
/><p>Most of flattened relationships are treated as read-only by Cayenne. Only one
(the most commonly used) type is read/write. It is many-to-many (n:m) flattened relationships
with a single join table.</p></td></tr></table></div>
<p>To map an ObjRelationship to a chain of DbRelationships, select ObjRelationship table
row and click "Edit Relationship" button in the bottom right. "ObjRelationship Inspector"
dialog will appear.</p>

<p><img src="/confluence/download/attachments/10544/objrelationship-path-selection.jpg"
align="absmiddle" border="0" /></p>

<p>The dialog contains a DbRelationship table. Clicking on each row in this table will
show valid choices of DbRelationships. Once you add a "chain" component, another row automatically
opens below, so you can build a chain of arbitrary length.</p>
<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td><b>Join Table Tip</b><br
/><p>If you flatten across a join table and this join table was mapped to an ObjEntity
(and a correspoding Java class), such ObjEntity can be deleted, as it is no longer needed.
Underlying DbEntity must be preserved.</p></td></tr></table></div>

<p>Further information about flattened relationships can be <a href="/confluence/display/CAYDOC/Flattened+Relationships"
title="Flattened Relationships">found here</a>.</p>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href=""
class="grey">Change Notification Preferences</a>

       <a href="">View
       <a href="">View
       <a href=";showCommentArea=true#addcomment">Add

View raw message