On 1-Aug-08, at 8:33 PM, Gustavo Pizano wrote:
Hello everyone, I just wanted to ask a noob question. Everywhere I look I see about the EditingConext, as I know, it function its to hold instances of the EO's so they can interact each other and so.
in the tutorials and the documentations, they talk most of the part about the defaultEditingContext, from the session, or the apllication, so my question is, when its necessary to use the defaultEditingContext, and to create a new one?.
This thing about the EditingContext its spining my head a little.
Tutorials generally don't use anything other than the defaultEditingContext because it adds a layer of complexity that the authors (I assume) feel will detract from the core purpose of the tutorial.
However, this tends to give beginners a false impression of how most real-world applications are written and also fails to demonstrate the pitfalls of a single EC design.
Lets take a (completely contrived) example:
Your application is using the defaultEditingContext. Your user enters a form that creates a new EO. Half way through they decide to abort and hit the back button a couple of times and go somewhere else in the site.
The defaultEditingContext is now dirtied with that new EO. If the user later performs any action that calls saveChanges on the defaultEC it will try and commit the EO, it might fail giving your user a completely unexplainable validation error, or it might succeed saving unwanted and probably invalid data.
So my general rule of thumb is to never use the defaultEditingContext for any edit actions. I always create new ECs for any task that is going to require editing.
Using Project Wonder's ERXEC makes this particularly painless as it handles the necessary EC locking automagically.
Other options are documented here: <
http://wiki.objectstyle.org/confluence/display/WO/EOF-Using+EOF-Context+and+Database+Locking>
;david
--
David LeBer
Codeferous Software
'co-def-er-ous' adj. Literally 'code-bearing'
site:
http://codeferous.comblog:
http://davidleber.net
profile:
http://www.linkedin.com/in/davidleber
twitter:
http://twitter.com/rebeld
--
Toronto Area Cocoa / WebObjects developers group:
http://tacow.org