Re: Shared editing context: rules of engagement
Re: Shared editing context: rules of engagement
- Subject: Re: Shared editing context: rules of engagement
- From: Dov Rosenberg <email@hidden>
- Date: Thu, 19 Apr 2007 10:40:43 -0400
- Thread-topic: Shared editing context: rules of engagement
We have been using the SharedEditingContext for a couple of years and have
finally gotten it pretty stable and useful. Here are some things we did:
1. Make sure to set the reference to the SharedEditingContext to null on ANY
regular editing context that you create i.e. Doing
_wec.setSharedEditingContext( null );
2. Retrieve the data you need into the shared editing context your self -
don't try to grab it from somewhere else. If you have to use
localInstanceOfObject() to get a copy
3. Never make any changes to an EO in the scope of the shared editing
context - i.e. Don't do anything like saveChanges(). If you need to make
changes create a new editingcontext, retrieve the data and then save it
there (observing rule #1). The object store coordinator will notify the
shared editing context of the change for you
4. If you are using the defaultSharedEditing context you don't need to lock
anything. Make sure that you DO lock any editing contexts that you create
manually and make sure they get unlocked properly (in the FINALLY block)
If you obey these rules things should behave nicely, if you stray at all you
are in for a world of bizarre behaviors and frustrating issues that are a
PIA to debug.
Good luck
--
Dov Rosenberg
Inquira
Knowledge Management Experts
http://www.inquira.com
On 4/19/07 2:42 AM, "Lachlan Deck" <email@hidden> wrote:
> Hi all,
>
> just wanting to clarify the do's/don'ts...
>
> I'm getting "Cannot obtain globalId for an object which is registered
> in an other than the databaseContext's active editingContext..."
>
> Okay, my understanding is that you ought _not_ have relationships
> going from a shared entity to a non-shared entity. Fine, so when the
> application starts up I've got some code that removes any such
> relations from the entities as they are registered (but leaving
> intact the relations from the non-shared to the shared). This allows
> me to specify an array property of "SharedEntities" relevant to that
> application.
>
> Now according to the api, I can create a regular editing context,
> fetch the object into it, change it and save and that'll be all there
> is to it. Nice theory.
>
> I'm actually not needing to change that object but am setting the
> relationship from a non-shared entity to the shared one. However the
> exception I'm an exception that's preventing me from saving the context.
>
> // Okay so I'm creating a editing context for editing like so:
> public MyEditingContext editingContext() {
> if ( _wec == null ) {
> _wec = new MyEditingContext( clientForRequest( context().request() );
> _wec.setSharedEditingContext( null );
> _wec.setStopsValidationAfterFirstError( false );
> }
> }
>
> // and in the awakeFromInsertion(EOEditingContext) I'm doing the
> following:
> {
> if has reverse relation
> // Note: this is where it's useful Mike :-)
> addObjectToBothSidesOfRelationshipWithKey( aClient, key );
> else
> takeValueForKey( aClient, key );
> }
>
> Any ideas? What have I missed?
> Thanks muchly...
>
> with regards,
> --
>
> Lachlan Deck
>
>
> [2007-04-19 15:57:53 EST] <WorkerThread14>
> <com.webobjects.appserver._private.WOComponentRequestHandler>:
> Exception occurred while handling request:
> java.lang.RuntimeException: <WOLongResponsePage> Exception occurred
> in long response thread: com.webobjects.foundation.NSForwardException
> [java.lang.IllegalStateException] Cannot obtain globalId for an
> object which is registered in an other than the databaseContext's
> active editingContext
> <...>
> [2007-04-19 15:57:53 EST] <WorkerThread14>
> java.lang.RuntimeException: <WOLongResponsePage> Exception occurred
> in long response thread: com.webobjects.foundation.NSForwardException
> [java.lang.IllegalStateException] Cannot obtain globalId for an
> object which is registered in an other than the databaseContext's
> active editingContext, object: {values = {webServicesPass = "**";
> collegeDomains = "<com.webobjects.eocontrol._EOCheapCopyMutableArray
> 3228a1 (<EOAccessArrayFaultHandler collegeDomains
> _EOIntegralKeyGlobalID[College (java.lang.Long)3]>)>"; promotions =
> "<com.webobjects.eocontrol._EOCheapCopyMutableArray 278e83
> (<EOAccessArrayFaultHandler promotions _EOIntegralKeyGlobalID[College
> (java.lang.Long)3]>)>"; created = 2006-06-23 07:45:05 Etc/GMT;
> modified = 2006-06-23 07:45:05 Etc/GMT; name = "Some name"; sites =
> "<com.webobjects.eocontrol._EOCheapCopyMutableArray 1a5ec6c
> (<EOAccessArrayFaultHandler sites _EOIntegralKeyGlobalID[College
> (java.lang.Long)3]>)>"; courses =
> "<com.webobjects.eocontrol._EOCheapCopyMutableArray 61cd2
> (<EOAccessArrayFaultHandler courses _EOIntegralKeyGlobalID[College
> (java.lang.Long)3]>)>"; isDeleted = false; nationalProviderCode =
> <com.webobjects.foundation.NSKeyValueCoding$Null>; messageTemplates =
> "<com.webobjects.eocontrol._EOCheapCopyMutableArray 5dfaf1
> (<EOAccessArrayFaultHandler messageTemplates _EOIntegralKeyGlobalID
> [College (java.lang.Long)3]>)>"; preferences =
> "<com.webobjects.eocontrol._EOCheapCopyMutableArray fd66a5
> (<EOAccessArrayFaultHandler preferences _EOIntegralKeyGlobalID
> [College (java.lang.Long)3]>)>"; courseClasses =
> "<com.webobjects.eocontrol._EOCheapCopyMutableArray 1ef7de4
> (<EOAccessArrayFaultHandler courseClasses _EOIntegralKeyGlobalID
> [College (java.lang.Long)3]>)>"; categories =
> "<com.webobjects.eocontrol._EOCheapCopyMutableArray 10980e7
> (<EOAccessArrayFaultHandler categories _EOIntegralKeyGlobalID[College
> (java.lang.Long)3]>)>"; webServicesLogin = "iscd"; rooms =
> "<com.webobjects.eocontrol._EOCheapCopyMutableArray 44d990
> (<EOAccessArrayFaultHandler rooms _EOIntegralKeyGlobalID[College
> (java.lang.Long)3]>)>"; courseSessions =
> "<com.webobjects.eocontrol._EOCheapCopyMutableArray 14e4e31
> (<EOAccessArrayFaultHandler courseSessions _EOIntegralKeyGlobalID
> [College (java.lang.Long)3]>)>"; subcategories =
> "<com.webobjects.eocontrol._EOCheapCopyMutableArray b85c17
> (<EOAccessArrayFaultHandler subcategories _EOIntegralKeyGlobalID
> [College (java.lang.Long)3]>)>"; tutors =
> "<com.webobjects.eocontrol._EOCheapCopyMutableArray 1b5391b
> (<EOAccessArrayFaultHandler tutors _EOIntegralKeyGlobalID[College
> (java.lang.Long)3]>)>"; webServicesSecurityCode =
> <com.webobjects.foundation.NSKeyValueCoding$Null>; }; this =
> "<com.ish.willow.college.model.College 7e8c4d _EOIntegralKeyGlobalID
> [College (java.lang.Long)3]>"; }, databaseContext:
> com.webobjects.eoaccess.EODatabaseContext@c743eb, object's
> editingContext:
> com.webobjects.eocontrol.EOSharedEditingContext@ba5c7a,
> databaseContext's active editingContext:
> com.ish.willow.eocontrol.WillowEditingContext@1a78071: Failed to save
> enrolments!
> at
> com.webobjects.woextensions.WOLongResponsePage.pageForException
> (WOLongResponsePage.java:205)
> at com.webobjects.woextensions.WOLongResponsePage.refresh
> (WOLongResponsePage.java:244)
> at
> com.webobjects.woextensions.WOLongResponsePage.invokeAction
> (WOLongResponsePage.java:224)
> at com.webobjects.appserver.WOSession.invokeAction
> (WOSession.java:1166)
> at com.webobjects.appserver.WOApplication.invokeAction
> (WOApplication.java:1375)
> at
> com.webobjects.appserver._private.WOComponentRequestHandler._dispatchWit
> hPreparedPage(WOComponentRequestHandler.java:196)
> at
> com.webobjects.appserver._private.WOComponentRequestHandler._dispatchWit
> hPreparedSession(WOComponentRequestHandler.java:287)
> at
> com.webobjects.appserver._private.WOComponentRequestHandler._dispatchWit
> hPreparedApplication(WOComponentRequestHandler.java:322)
> at
> com.webobjects.appserver._private.WOComponentRequestHandler._handleReque
> st(WOComponentRequestHandler.java:358)
> at
> com.webobjects.appserver._private.WOComponentRequestHandler.handleReques
> t(WOComponentRequestHandler.java:432)
> at com.webobjects.appserver.WOApplication.dispatchRequest
> (WOApplication.java:1306)
> at
> com.ish.webobjects.appserver.ISHApplication.dispatchRequest
> (ISHApplication.java:807)
> at
> com.ish.willow.college.appserver.Application.dispatchRequest
> (Application.java:172)
> at com.webobjects.appserver._private.WOWorkerThread.runOnce
> (WOWorkerThread.java:173)
> at com.webobjects.appserver._private.WOWorkerThread.run
> (WOWorkerThread.java:254)
> at java.lang.Thread.run(Thread.java:534)
>
>
> _______________________________________________
> 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
_______________________________________________
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