cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [CONF] Apache Cayenne Documentation > Delete Rules
Date Sun, 27 Dec 2009 15:09: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="">Delete
     <h4>Page <b>edited</b> by             <a href="">Andrus
     <div class="notificationGreySide">
         <h3><a name="DeleteRules-DeleteRules"></a>Delete Rules</h3>

<p>One of the columns in the Modeler ObjRelationships panel is "Delete Rule". It tells
Cayenne what to do with related objects when a <b>source object</b> of the relationship
is deleted. Cayenne will use this delete rule to perform cleanup of other objects after a
given object was deleted from the graph. </p>

<p>Default delete rule is <b>No Action</b>, meaning just that - when an
object is deleted, no changes should happen to objects related to this object via a given
relationship. Though this is a default, it is not very useful, and can lead to object graph
corruption in many cases. It is developer responsibility to select a more meaningful delete
rule. The choices are: "Nullify", "Cascade" and "Deny". Each one of them is explained below.</p>

	<li><b>Nullify Rule:</b> When a <b>source object</b> is deleted,
any pointers from the <b>target object(s)</b> back to the deleted object will
be reset to null. This presumes an existence of reverse ObjRelationship for a given ObjRelationship.
If no such reverse relationship exist, "Nullify" rule has no effect. This rule should be used
when target object(s) of relationship can exist without the source object and do not depend
on it. Example: <tt>Employee.toDepartment</tt> relationship logically should use
"Nullify" rule.</li>

	<li><b>Cascade Rule:</b> When a <b>source object</b> is deleted,
any of the <b>target object(s)</b> will be deleted too. This may cause the whole
tree of objects to be deleted with one command. This rule should be used when target object(s)
of relationship can not exist without the source object. Example: <tt>Department.employeeArray</tt>
relationship may use "Cascade" rule.</li>

	<li><b>Deny Rule:</b> When a <b>source object</b> is being
deleted, but it has at least one <b>target object</b> this rule would generate
a runtime exception on delete attempt. This rule is usually a reflection of certain business
rules in the application. Example: <tt>Department.employeeArray</tt> relationship
may use "Deny" rule if there is an application requirement that explicitly states that non-empty
departments can not be deleted.</li>

<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>Cayenne Delete Rules
vs. DB Delete Rules</b><br />Some databases allow to define delete rules logically
similar to the rules described above. Cayenne rules differ from DB rules in that they deal
with object graph instead of relational schema. Some changes to the object graph will result
in database operations (e.g. resetting FK to NULL as a result of Nullify rule), some others
will not (e.g. removing a deleted DataObject from the to-many array as a result of another
Nullify rule).</td></tr></table></div>
     <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