You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Øyvind Harboe <oy...@zylin.com> on 2006/12/03 20:28:04 UTC

Delete rules

I have discovered that I assumed that "Nullify" was default.

Reading the wiki page below, I miss an explanation of why "No action"
is default or why "No action" exists at all. I would have preferred
some default that either "did what I expected" or forced me to
consider this problem and solve it upfront(the obvious cost being that
one is forced to learn another concept upfront).

Can "No action" be overridden by subclassing to do something reasonable?

What worries me is that "No action" is a bug waiting to happen. It
certainly bit me(I've screwed this up in three Cayenne projects before
I learned of the the default delete rule). The precise behavior of "No
action" is somewhat random.

- Delete + commit => relationship might  exists depending on how many
objects are cached in Cayenne.
- Delete + commit + logout(create new DataContext) => relationship no
longer exists(same as above w/"Nullify")

http://cwiki.apache.org/confluence/display/CAYDOC/Delete+Rules

I was also somewhat surprised that validateForDelete() does not take
the deleteRule="Deny" into account and that the exception only occurs
when deleteObject() is invoked.

-- 
Øyvind Harboe
http://www.zylin.com

Re: Delete rules

Posted by Peter Karich <pe...@yahoo.de>.
Hallo!

Before I get the NPE in the setToManyTarget
(please see the 'NullPointerException when setting deletion rules' thread)

I get one in setToOneTarget, because I have the 'No Action'-delete rule 
for the relationship timeintervals->room.
So I vote for 'Nullify' action :-), this avoids the NPE ...
But we should highlight the phrase in the docs:

"Though this is a default (the 'No Action'), 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."

Peter.

		
___________________________________________________________ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de

Re: Delete rules

Posted by Cris Daniluk <cr...@gmail.com>.
I think the most ideal would be no default.. half the time I've left
them as is (regardless of what default value there could have been),
I've regretted it :)

Of course, that probably isn't practical. But still, I think there is
definitely a moral... one size doesn't fit all for delete rules, and
user consideration should be given to them. Maybe we can highlight it
in documentation?

Cris


On 12/4/06, Michael Gentry <bl...@gmail.com> wrote:
> I actually prefer the No Action default.  To me, this doesn't do anything
> unexpected.  Perhaps the best solution would be a preference setting where
> you can choose your default?
>
> /dev/mrg
>
>
> On 12/3/06, Andrus Adamchik <an...@objectstyle.org> wrote:
> >
> > Note that the default choices are sensitive to the preferences and
> > conventions used in modeling the DB schema. E.g. "Nullify/Nullify"
> > for a pair of complimentary relationships will result in exceptions
> > if FK's are not nullable. That's what I meant by "correct defaults" -
> > they are not always obvious. But Nullify can probably be a "good
> > enough" default.
> >
> > Andrus
> >
> >
> > On Dec 3, 2006, at 11:12 PM, Øyvind Harboe wrote:
> > > On 12/3/06, Tore Halset <ha...@pvv.ntnu.no> wrote:
> > >> Hello.
> > >>
> > >> I think "Nullify" is a better default than "No Action" as it matches
> > >> what I want to do in most cases. I sometimes use "Cascade", but it is
> > >> not a good default value :)
> > >
> > > I switched to using nullify (text search & replace) as default rule
> > > and CayenneModeler threw up  warnings(I forget precisely which), but I
> > > had to switch some relationships to "Deny"....
> > >
> > >
> > > --
> > > Øyvind Harboe
> > > http://www.zylin.com
> >
> >
>
>

Re: Delete rules

Posted by Michael Gentry <bl...@gmail.com>.
I actually prefer the No Action default.  To me, this doesn't do anything
unexpected.  Perhaps the best solution would be a preference setting where
you can choose your default?

/dev/mrg


On 12/3/06, Andrus Adamchik <an...@objectstyle.org> wrote:
>
> Note that the default choices are sensitive to the preferences and
> conventions used in modeling the DB schema. E.g. "Nullify/Nullify"
> for a pair of complimentary relationships will result in exceptions
> if FK's are not nullable. That's what I meant by "correct defaults" -
> they are not always obvious. But Nullify can probably be a "good
> enough" default.
>
> Andrus
>
>
> On Dec 3, 2006, at 11:12 PM, Øyvind Harboe wrote:
> > On 12/3/06, Tore Halset <ha...@pvv.ntnu.no> wrote:
> >> Hello.
> >>
> >> I think "Nullify" is a better default than "No Action" as it matches
> >> what I want to do in most cases. I sometimes use "Cascade", but it is
> >> not a good default value :)
> >
> > I switched to using nullify (text search & replace) as default rule
> > and CayenneModeler threw up  warnings(I forget precisely which), but I
> > had to switch some relationships to "Deny"....
> >
> >
> > --
> > Øyvind Harboe
> > http://www.zylin.com
>
>

Re: Delete rules

Posted by Andrus Adamchik <an...@objectstyle.org>.
Note that the default choices are sensitive to the preferences and  
conventions used in modeling the DB schema. E.g. "Nullify/Nullify"  
for a pair of complimentary relationships will result in exceptions  
if FK's are not nullable. That's what I meant by "correct defaults" -  
they are not always obvious. But Nullify can probably be a "good  
enough" default.

Andrus


On Dec 3, 2006, at 11:12 PM, Øyvind Harboe wrote:
> On 12/3/06, Tore Halset <ha...@pvv.ntnu.no> wrote:
>> Hello.
>>
>> I think "Nullify" is a better default than "No Action" as it matches
>> what I want to do in most cases. I sometimes use "Cascade", but it is
>> not a good default value :)
>
> I switched to using nullify (text search & replace) as default rule
> and CayenneModeler threw up  warnings(I forget precisely which), but I
> had to switch some relationships to "Deny"....
>
>
> -- 
> Øyvind Harboe
> http://www.zylin.com


Re: Delete rules

Posted by Øyvind Harboe <oy...@zylin.com>.
On 12/3/06, Tore Halset <ha...@pvv.ntnu.no> wrote:
> Hello.
>
> I think "Nullify" is a better default than "No Action" as it matches
> what I want to do in most cases. I sometimes use "Cascade", but it is
> not a good default value :)

I switched to using nullify (text search & replace) as default rule
and CayenneModeler threw up  warnings(I forget precisely which), but I
had to switch some relationships to "Deny"....


-- 
Øyvind Harboe
http://www.zylin.com

Re: Delete rules

Posted by Tore Halset <ha...@pvv.ntnu.no>.
Hello.

I think "Nullify" is a better default than "No Action" as it matches  
what I want to do in most cases. I sometimes use "Cascade", but it is  
not a good default value :)

  - Tore.

On Dec 3, 2006, at 20:47, Andrus Adamchik wrote:

> Just like with the outer joins discussion that you initiated some  
> time ago, the answer here is that until a smart enough algorithm is  
> designed to infer *correct* defaults for all combinations of  
> relationships, Cayenne absolves itself from modifying the object  
> graph, leaving it up to the user. Hence "No Action".
>
> On the other hand "Nullify", while not an ideal default, is  
> probably the closest to "forcing [...] to consider [...] problem  
> and solve it upfront" paradigm, as it will result in  
> RuntimExceptions when used gratuitously. So maybe you are right  
> about it.
>
> Anybody else has thoughts on that?
>
> Andrus
>
>
>
> On Dec 3, 2006, at 9:28 PM, Øyvind Harboe wrote:
>
>> I have discovered that I assumed that "Nullify" was default.
>>
>> Reading the wiki page below, I miss an explanation of why "No action"
>> is default or why "No action" exists at all. I would have preferred
>> some default that either "did what I expected" or forced me to
>> consider this problem and solve it upfront(the obvious cost being  
>> that
>> one is forced to learn another concept upfront).
>>
>> Can "No action" be overridden by subclassing to do something  
>> reasonable?
>>
>> What worries me is that "No action" is a bug waiting to happen. It
>> certainly bit me(I've screwed this up in three Cayenne projects  
>> before
>> I learned of the the default delete rule). The precise behavior of  
>> "No
>> action" is somewhat random.
>>
>> - Delete + commit => relationship might  exists depending on how many
>> objects are cached in Cayenne.
>> - Delete + commit + logout(create new DataContext) => relationship no
>> longer exists(same as above w/"Nullify")
>>
>> http://cwiki.apache.org/confluence/display/CAYDOC/Delete+Rules
>>
>> I was also somewhat surprised that validateForDelete() does not take
>> the deleteRule="Deny" into account and that the exception only occurs
>> when deleteObject() is invoked.
>>
>> -- 
>> Øyvind Harboe
>> http://www.zylin.com
>>
>


Re: Delete rules

Posted by Andrus Adamchik <an...@objectstyle.org>.
Just like with the outer joins discussion that you initiated some  
time ago, the answer here is that until a smart enough algorithm is  
designed to infer *correct* defaults for all combinations of  
relationships, Cayenne absolves itself from modifying the object  
graph, leaving it up to the user. Hence "No Action".

On the other hand "Nullify", while not an ideal default, is probably  
the closest to "forcing [...] to consider [...] problem and solve it  
upfront" paradigm, as it will result in RuntimExceptions when used  
gratuitously. So maybe you are right about it.

Anybody else has thoughts on that?

Andrus



On Dec 3, 2006, at 9:28 PM, Øyvind Harboe wrote:

> I have discovered that I assumed that "Nullify" was default.
>
> Reading the wiki page below, I miss an explanation of why "No action"
> is default or why "No action" exists at all. I would have preferred
> some default that either "did what I expected" or forced me to
> consider this problem and solve it upfront(the obvious cost being that
> one is forced to learn another concept upfront).
>
> Can "No action" be overridden by subclassing to do something  
> reasonable?
>
> What worries me is that "No action" is a bug waiting to happen. It
> certainly bit me(I've screwed this up in three Cayenne projects before
> I learned of the the default delete rule). The precise behavior of "No
> action" is somewhat random.
>
> - Delete + commit => relationship might  exists depending on how many
> objects are cached in Cayenne.
> - Delete + commit + logout(create new DataContext) => relationship no
> longer exists(same as above w/"Nullify")
>
> http://cwiki.apache.org/confluence/display/CAYDOC/Delete+Rules
>
> I was also somewhat surprised that validateForDelete() does not take
> the deleteRule="Deny" into account and that the exception only occurs
> when deleteObject() is invoked.
>
> -- 
> Øyvind Harboe
> http://www.zylin.com
>