Re: Shared EC problems for a newbie
Re: Shared EC problems for a newbie
- Subject: Re: Shared EC problems for a newbie
- From: Art Isbell <email@hidden>
- Date: Thu, 23 Feb 2006 13:59:39 -1000
On Feb 23, 2006, at 12:37 PM, Timmy wrote:
I've got a set of EOs that are fetched in Application by a
EOSharedEditingContext. These are objects that are used to populate
lists in my application. I have a component where an admin type can
(hopefully) alter these objects when/if truly necessary - but it
would be rare. So, they are truly "read mostly"/"write rarely"
objects.
I have a method that attempts to edit one of these EOs and to
accomplish that attempts to get a copy of the EO in a local editing
context.
In case you didn't see Ben Trumbull's message about updating shared
objects:
On Nov 16, 2005, at 1:45 PM, Ben Trumbull wrote:
People successfully use shared ECs in concurrent apps, although
updating shared objects is very difficult to do correctly. I've
seen it done by taking a large granularity lock in the request
handler. However, the following approach *should* work, and be
less drastic than that sledgehammer:
regularEC = new EOEditingContext();
regularEC.lock();
try {
regularEC.setSharedEditingContext(null);
// fetch or fault the currently shared objects to update into
regularEC
// update the ex-shared objects in regularEC
sharedEC.lock();
objectStoreCoordinator.lock();
try {
regularEC.saveChanges();
} finally {
objectStoreCoordinator.unlock();
sharedEC.unlock();
}
} finally {
regularEC.unlock();
regularEC = null;
}
The ordering of the lock/unlocking is important and must not be
changed.
In my method I have the following line:
EntityName _myLocalEO = (EntityName)
EOUtilities.localInstanceOfObject(myPageContext(),entityItem());
myPageContext() returns a new local EOEditingContext that is a
child of the session's defaultEditingContext (I think). It is
instantiated like this:
setMyPageContext(new EOEditingContext((Session)session
().defaultEditingContext()));
If myPageContext() is the editing context you are using to update a
shared object, be sure to send it a setSharedEditingContext(null)
message.
The line calling EOUtilities.localInstanceOfObject() above throws a
null pointer exception and I can't figure out exactly why this is
happening. Below is the crash dump starting with my method
(removeDosTypeFromUse()). None of the arguments I am passing into
localInstanceOfObject are null.
[2006-02-23 14:11:10 PST] <WorkerThread0>
java.lang.NullPointerException
at com.webobjects.eocontrol.EOEditingContext.faultForGlobalID
(EOEditingContext.java:3678)
at com.webobjects.eoaccess.EOUtilities.localInstanceOfObject
(EOUtilities.java:942)
at DosCodesPage.removeDosTypeFromUse(DosCodesPage.java:173)
Can anyone point me in the right direction?
Ensure that entityItem() is in an editing context.
Aloha,
Art
_______________________________________________
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