Re: Can't modify EO objects! ARGH! =(
Re: Can't modify EO objects! ARGH! =(
- Subject: Re: Can't modify EO objects! ARGH! =(
- From: Chuck Hill <email@hidden>
- Date: Thu, 17 Jul 2003 16:41:54 -0700
- Organization: Global Village Consulting, Inc.
Art Isbell wrote:
On Thursday, July 17, 2003, at 11:59 AM, Albert Jagnow wrote:
I am confused by the pattern you list below. I have had more problems
doing insert before populate.
As Chuck stated, these problems can be dealt with by making the
changes in an editing context whose parent is the session's default
editing context. If you decide not to save these changes, set this
editing context to null so it is garbage collected. The session's
default editing context won't realize any changes have been made.
If you do decide to save the changes, send a saveChanges() message
to the nested editing context which moves the changes up to the
session's default editing context. If this parent is the session's
default editing context, then send a saveChanges() message to it to save
to the DB.
And as a reminder: if you do go this route (or the peer editing
context way), then *you* are *responsible* for locking and unlocking
these editing contexts. Failure to do so may result in even worse
problems than modifiying objects not in an editing context (which is
not to be construed as a reccomendation to do so!).
Another possibly less flexible approach is to use just the default
editing context. If you make changes that you don't want to save, send
the editing context a revert() message.
As a slight variant, call session().defaultEditingContext().revert()
before starting a new set of changes. Either way, a little less
elegant than you might care for.
EOF knows what SQL to generate based on the changes made to objects
in an editing context. When you make changes to an object that's not in
an editing context, then EOF can't possibly know what SQL to generate to
apply these changes to the DB. You can get lucky by making changes that
don't affect the SQL generated, but you can also get unlucky such that
the changes that you have made won't get saved to the DB. One example
of missed changes are foreign keys that aren't updated when a
relationship value is set in an object that's outside of an editing
context. So always insert a new object into an editing context before
you make any changes to it.
Now that Art mentions it, another problem that can happen is
subsequent updates to the object go unnoticed by EOF.
Chuck
--
Chuck Hill email@hidden
Global Village Consulting Inc. http://www.global-village.net
Progress is the mother of all problems.
- G. K. Chesterton
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.