Re: Mysterious EditingContext Swap
Re: Mysterious EditingContext Swap
- Subject: Re: Mysterious EditingContext Swap
- From: Ken Anderson <email@hidden>
- Date: Tue, 01 Aug 2006 23:09:01 -0400
Owen,
Are you paraphrasing the error message? I have to admit, I've never
heard of a database context's "active" editing context. Is there
other code besides this? Have you isolated this code out in a
separate project?
Ken
On Aug 1, 2006, at 10:42 PM, Owen McKerrow wrote:
Hi All,
Im having issues with an editing context that seems to somehow be
switching behind my back.
Vitals : OS X 10.4.7 WO 5.3 Java 1.4.2
OK first an explaination :
On our login in page we check if the user already has an account,
if so log them in, if not make them one attach them to an instance
of company and then log them in. From a clean DB i.e. no users in
it I can log in as user one and it makes the user fine. I can then
re-log in as this user. If I log in as another user I get a error
saying that the company object is in another editing context.
So I added in debug statements to check what was happening with it.
And it seems between grabbing the company, creating a new user and
then doing addObjectToBothSidesOfRelationship, my active editing
context changes.
Short Version ( debug statements spaced in-between the lines of
code ) :
//Editing Context just been made :
com.webobjects.eocontrol.EOEditingContext@aab7d
Company theCompany = (Company)
com.webobjects.eoaccess.EOUtilities.objectMatchingKeyAndValue
(ec,"Company","logonIdentifier","UOW");
System.out.println("Company : " + theCompany.editingContext());
//Company : com.webobjects.eocontrol.EOEditingContext@aab7d
if( theCompany != null ) {
r = ( Recipient)
com.webobjects.eoaccess.EOUtilities.createAndInsertInstance
(ec,"Recipient");
System.out.println("New Recipient : " + r.editingContext());
//New Recipient : com.webobjects.eocontrol.EOEditingContext@aab7d
r.setLogonIdentifier(userName);
r.addObjectToBothSidesOfRelationshipWithKey
(theCompany,"company"); //Error is thrown on this line
Short error ( referring to theCompany ):
Cannot obtain globalId for an object which is registered in an
other than the databaseContext's active editingContext
databaseContext: com.webobjects.eoaccess.EODatabaseContext@edfb95
object's editingContext:
com.webobjects.eocontrol.EOEditingContext@aab7d
databaseContext's active editingContext:
com.webobjects.eocontrol.EOEditingContext@883540
As you can see the Company's editing context is aab7d, however when
I call addObjectToBothSidesOfRelationshipWithKey the active editing
context is apparently 883540.
How is the active editing context "swapping" ? In fact where is if
getting this active editing context from ?
Anyone have any ideas ?
Thanks
Owen
PS Heres the "fuller" version
Long Version :
The code :
ec = new EOEditingContext();
try {
//search the recipient table for the username
Recipient r = null;
NSMutableDictionary dic = new NSMutableDictionary();
dic.setObjectForKey(userName,"logon");
NSArray temp =
EOUtilities.objectsWithFetchSpecificationAndBindings
(ec,"Recipient","RecipSearch",dic);
if( temp.count() > 0 ) {
r = (Recipient)temp.lastObject();
System.out.println("Old : " + r.surname() + r.logonIdentifier()
+ r.editingContext());
}
System.out.println("Editing after search for old : " + ec);
//insert new row in database if recipient does not exist
if (r==null) {
System.out.println("Editin Context at start of create : " + ec);
Company theCompany = (Company)
com.webobjects.eoaccess.EOUtilities.objectMatchingKeyAndValue
(ec,"Company","logonIdentifier","UOW");
System.out.println("Company : " + theCompany.editingContext());
if( theCompany != null ) {
r = ( Recipient)
com.webobjects.eoaccess.EOUtilities.createAndInsertInstance
(ec,"Recipient");
System.out.println("New Recipient : " + r.editingContext());
r.setLogonIdentifier(userName);
r.addObjectToBothSidesOfRelationshipWithKey
(theCompany,"company");
The Debug Statements :
Logged in as user 1 ( all works fine ) :
Editing Context just been made :
com.webobjects.eocontrol.EOEditingContext@65a43b
Session has been created.
Editing Context at start of checkRecipient :
com.webobjects.eocontrol.EOEditingContext@65a43b
Editing after search for old :
com.webobjects.eocontrol.EOEditingContext@65a43b
Editin Context at start of create :
com.webobjects.eocontrol.EOEditingContext@65a43b
Company : com.webobjects.eocontrol.EOEditingContext@65a43b
New Recipient : com.webobjects.eocontrol.EOEditingContext@65a43b
new : McKerrowowencom.webobjects.eocontrol.EOEditingContext@65a43b
editing Context : com.webobjects.eocontrol.EOEditingContext@65a43b
Session Terminate
Log in for second time as user 1 ( all works fine ) :
Editing Context just been made :
com.webobjects.eocontrol.EOEditingContext@6487a9
Session has been created.
Editing Context at start of checkRecipient :
com.webobjects.eocontrol.EOEditingContext@6487a9
Old : McKerrowowencom.webobjects.eocontrol.EOEditingContext@6487a9
Editing after search for old :
com.webobjects.eocontrol.EOEditingContext@6487a9
editing Context : com.webobjects.eocontrol.EOEditingContext@6487a9
Session Terminate
Log in As User 2 :
Editing Context just been made :
com.webobjects.eocontrol.EOEditingContext@aab7d
Session has been created.
Editing Context at start of checkRecipient :
com.webobjects.eocontrol.EOEditingContext@aab7d
Editing after search for old :
com.webobjects.eocontrol.EOEditingContext@aab7d
Editin Context at start of create :
com.webobjects.eocontrol.EOEditingContext@aab7d
Company : com.webobjects.eocontrol.EOEditingContext@aab7d
New Recipient : com.webobjects.eocontrol.EOEditingContext@aab7d
Long Error :
[2006-08-02 12:15:34 EST] <WorkerThread3>
<com.webobjects.appserver._private.WOComponentRequestHandler>:
Exception occurred while handling request:
java.lang.IllegalStateException: Cannot obtain globalId for an
object which is registered in an other than the databaseContext's
active editingContext, object: {values = {companyName = "University
of Wollongong"; recipient =
"<com.webobjects.eocontrol._EOCheapCopyMutableArray f65b0e
(<EOAccessArrayFaultHandler recipient _EOIntegralKeyGlobalID
[Company (java.math.BigDecimal)1]>)>"; dateCreated =
<com.webobjects.foundation.NSKeyValueCoding$Null>; logonIdentifier
= "UOW"; trackingObject =
"<com.webobjects.eocontrol._EOCheapCopyMutableArray 6a1e78
(<EOAccessArrayFaultHandler trackingObject _EOIntegralKeyGlobalID
[Company (java.math.BigDecimal)1]>)>"; }; this = "<Company 864d2
_EOIntegralKeyGlobalID[Company (java.math.BigDecimal)1]>"; },
databaseContext: com.webobjects.eoaccess.EODatabaseContext@edfb95,
object's editingContext:
com.webobjects.eocontrol.EOEditingContext@aab7d, databaseContext's
active editingContext:
com.webobjects.eocontrol.EOEditingContext@883540
[2006-08-02 12:15:34 EST] <WorkerThread3>
java.lang.IllegalStateException: Cannot obtain globalId for an
object which is registered in an other than the databaseContext's
active editingContext, object: {values = {companyName = "University
of Wollongong"; recipient =
"<com.webobjects.eocontrol._EOCheapCopyMutableArray f65b0e
(<EOAccessArrayFaultHandler recipient _EOIntegralKeyGlobalID
[Company (java.math.BigDecimal)1]>)>"; dateCreated =
<com.webobjects.foundation.NSKeyValueCoding$Null>; logonIdentifier
= "UOW"; trackingObject =
"<com.webobjects.eocontrol._EOCheapCopyMutableArray 6a1e78
(<EOAccessArrayFaultHandler trackingObject _EOIntegralKeyGlobalID
[Company (java.math.BigDecimal)1]>)>"; }; this = "<Company 864d2
_EOIntegralKeyGlobalID[Company (java.math.BigDecimal)1]>"; },
databaseContext: com.webobjects.eoaccess.EODatabaseContext@edfb95,
object's editingContext:
com.webobjects.eocontrol.EOEditingContext@aab7d, databaseContext's
active editingContext:
com.webobjects.eocontrol.EOEditingContext@883540
at com.webobjects.eoaccess.EODatabaseContext._globalIDForObject
(EODatabaseContext.java:4847)
at
com.webobjects.eoaccess.EODatabaseContext.databaseOperationForObject
(EODatabaseContext.java:4964)
at com.webobjects.eoaccess.EODatabaseContext.valuesForKeys
(EODatabaseContext.java:6701)
at com.webobjects.eocontrol.EOObjectStoreCoordinator.valuesForKeys
(EOObjectStoreCoordinator.java:341)
at com.webobjects.eoaccess.EOQualifierSQLGeneration
$_KeyValueQualifierSupport.schemaBasedQualifierWithRootEntity
(EOQualifierSQLGeneration.java:418)
at com.webobjects.eoaccess.EOQualifierSQLGeneration
$Support._schemaBasedQualifierWithRootEntity
(EOQualifierSQLGeneration.java:165)
at
com.webobjects.eoaccess.EODatabaseChannel.selectObjectsWithFetchSpecif
ication(EODatabaseChannel.java:209)
at
com.webobjects.eoaccess.EODatabaseContext._objectsWithFetchSpecificati
onEditingContext(EODatabaseContext.java:3205)
at
com.webobjects.eoaccess.EODatabaseContext.objectsWithFetchSpecificatio
n(EODatabaseContext.java:3346)
at
com.webobjects.eocontrol.EOObjectStoreCoordinator.objectsWithFetchSpec
ification(EOObjectStoreCoordinator.java:539)
at
com.webobjects.eocontrol.EOEditingContext.objectsWithFetchSpecificatio
n(EOEditingContext.java:4114)
at
com.webobjects.eoaccess.EODatabaseContext.objectsForSourceGlobalID
(EODatabaseContext.java:4260)
at
com.webobjects.eocontrol.EOObjectStoreCoordinator.objectsForSourceGlob
alID(EOObjectStoreCoordinator.java:682)
at
com.webobjects.eocontrol.EOEditingContext.objectsForSourceGlobalID
(EOEditingContext.java:3965)
at com.webobjects.eoaccess.EODatabaseContext._fireArrayFault
(EODatabaseContext.java:4427)
at
com.webobjects.eoaccess.EOAccessArrayFaultHandler.completeInitializati
onOfObject(EOAccessArrayFaultHandler.java:70)
at com.webobjects.eocontrol._EOCheapCopyMutableArray.willRead
(_EOCheapCopyMutableArray.java:38)
at com.webobjects.eocontrol._EOCheapCopyMutableArray.count
(_EOCheapCopyMutableArray.java:92)
at com.webobjects.foundation.NSArray.containsObject(NSArray.java:639)
at
com.webobjects.eocontrol.EOCustomObject.includeObjectIntoPropertyWithK
ey(EOCustomObject.java:907)
at Company.addToRecipient(Company.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.webobjects.foundation.NSSelector._safeInvokeMethod
(NSSelector.java:120)
at
com.webobjects.eocontrol.EOCustomObject.addObjectToPropertyWithKey
(EOCustomObject.java:944)
at
com.webobjects.eocontrol.EOCustomObject.addObjectToBothSidesOfRelation
shipWithKey(EOCustomObject.java:1069)
at Main.checkRecipient(Main.java:229)
at Main.checkLogin(Main.java:122)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40anderhome.com
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