• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Object not being saved after refaulting and applying changed
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Object not being saved after refaulting and applying changed
      • From: Miguel Arroz <email@hidden>
References: 
 >Object not being saved after refaulting and applying changed (From: Miguel Arroz <email@hidden>)

  • Prev by Date: Object not being saved after refaulting and applying changed
  • Next by Date: Re: Object not being saved after refaulting and applying changed
  • Previous by thread: Object not being saved after refaulting and applying changed
  • Next by thread: Re: Object not being saved after refaulting and applying changed
  • Index(es):
    • Date
    • Thread