Re: Object not being saved after refaulting and applying changed
Re: Object not being saved after refaulting and applying changed
- Subject: Re: Object not being saved after refaulting and applying changed
- From: Chuck Hill <email@hidden>
- Date: Thu, 19 Jul 2007 16:02:17 -0700
On Jul 19, 2007, at 3:54 PM, Miguel Arroz wrote:
Hi!
I'm having a weird problem here. The situation is the following:
I have a context, where I have a freshly inserted EO, some non-
updated EOs, and some updated EOs. When I try to save and detect a
Optimistic locking exception, I need to deal with it by refaulting
all the objects (updated or not) from the DB, and reapplying the
changes to some of them.
So, I manually call refaultObject(object) to all objects I know
that were updated, and call refaultAllObjects for all the others
(because refaultAllObjects does NOT refault updated objects).
After than, I reapply the changes, and try to save. I'm
absolutely sure that I applied the changes, because I log one of
the properties of an updated object right before the saveChanges call.
Now, the amazing result is that some objects are saved, and some
are not! No SQL is generated for them, and so they are simply not
saved.
I looked arround, and say this: <http://lists.apple.com/archives/
webobjects-dev/2004/May/msg00377.html>. I tried to apply that hack,
but it didn't work. Is the bug 3389369 solved?
So... is this a bug from WO or am I doing something stupid? If
it's a bug, how can I do an workarround? If it's me doing stupid
things, what are those? :)
1. I doubt this is fixed in an released version.
2. I had other problems with doing it like this, so I don't really know.
3. Wonder doubtless has "totally cool code that I wrote" (quoting
Anjo here :-) that handles this much better.
4. Try this instead of refault:
/**
* Forces this object to be re-read from the database; the
snapshot and all editing contexts
* holding this object are updated. Merging or overwriting of
the changes is then handled by
* the editing context delegate. This method takes no action if
the object is pending insertion.
*
* @param anObject the object to be evaluated
*/
public static void refreshObject(EOEnterpriseObject anObject)
{
/** require [valid_theObject_param] anObject != null;
[in_ec] anObject.editingContext() !=
null; **/
// We can't just call editingContext().refreshObject() or
editingContext().refaultObject() the object here.
// That will result in fresh data only if the object is in a
single editing context.
// This seems like the safest way to get fresh data and
inform all of the other
// editing contexts that they need to update.
EOEditingContext ec = anObject.editingContext();
if ( ! ec.insertedObjects().containsObject(anObject))
{
EOQualifier thisObject =
EOUtilities.qualifierForEnterpriseObject(ec, anObject);
EOFetchSpecification fetchSpec = new EOFetchSpecification
(entityForSelf(anObject).name(), thisObject, NSArray.EmptyArray);
fetchSpec.setRefreshesRefetchedObjects(true);
anObject.editingContext().objectsWithFetchSpecification
(fetchSpec);
}
}
--
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems.
http://www.global-village.net/products/practical_webobjects
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden