• 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: Mysterious EditingContext Swap
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mysterious EditingContext Swap


  • Subject: Re: Mysterious EditingContext Swap
  • From: Chuck Hill <email@hidden>
  • Date: Wed, 2 Aug 2006 10:05:56 -0700


On Aug 1, 2006, at 8:50 PM, Owen McKerrow wrote:

Nope, not paraphrasing. You can see the full error message at bottom of the email.

The only time I have heard of the active editing context is for a save.

All EOF operations are serialized. The active editing context is the one that locked the object store (IIRC). You are not locking your editing contexts properly. My guess is that this is the root of your problem. Is this error consistent, or somewhat random?


Chuck


Nope haven't had the chnace yet to separate this out to its own project.


Heres the full code ( it includes our RADIUS authentication methods which I did paste before ):

// Generated by the WebObjects Assistant Mon Feb 07 14:26:32 Australia/Sydney 2005

import com.webobjects.foundation.*;
import com.webobjects.appserver.*;
import com.webobjects.eocontrol.*;
import com.webobjects.eoaccess.*;

import net.sourceforge.jradiusclient.*;
import net.sourceforge.jradiusclient.exception.*;

public class Main extends WOComponent {

    protected Application app;
	protected EOEditingContext ec;
    protected NSMutableDictionary bindings;


protected String userName;
protected String password;
protected String errorMessage;
protected boolean forgotPassword;
protected boolean thankyou;
protected boolean emailAddress;
protected boolean gotMobile;

private String secretHandshake;
private String hostName;
private RadiusClient rc;
private String exitCode;



//----------------------------- The Constructors ---------------------------------------------


    public Main( WOContext context ) throws Exception
	{
        super(context);

        app = (Application)Application.application();
		//ec = ((Session)session()).defaultEditingContext();
		ec = new EOEditingContext();
		System.out.println("Editing Context just been made : " + ec);
	//	((Session)session()).resetCrumbs();


		secretHandshake = "*********";

        hostName = "radius.uow.edu.au";
        RadiusClient rc = null;

		NSArray mems;
        forgotPassword = false;
		thankyou = false;
		emailAddress = false;
		gotMobile = false;

    }

//------------------------------- WOComponent Functions ---------------------------------------

    //Called when the Persons clicks the submit button to login
    public WOComponent checkLogin() throws Exception
    {
		errorMessage = "";
        WOComponent nextPage = null;


	//If both fields have some data in them
        if ( userName != null && password != null )
        {

            userName.trim();
            password.trim();
			

try {
rc = new RadiusClient(hostName, 1812,1813,secretHandshake,userName);
} catch(java.net.SocketException soex) {
app.setErrorMessage("Unable to create Radius Client due to failure to create socket!");
throw soex;
} catch(java.security.NoSuchAlgorithmException nsaex) {
app.setErrorMessage("Unable to create Radius Client due to failure to create MD5 MessageDigest!");
throw nsaex;
} catch(InvalidParameterException ivpex) {
app.setErrorMessage("Unable to create Radius Client due to invalid parameter! " + ivpex.getMessage() );
throw ivpex;
}


try {

boolean returned;
if (app.debugMode )
{
returned = true;
}
else
{
returned = authenticate(rc,password,null);
}


// Radius confirmed the userName and password are valid
if (returned)
{
nextPage = (Menu)pageWithName("Menu");
//check if the user is in the recipient table
checkRecipient();

}
else
{
errorMessage = "<span class=\"failure\">User name & Password incorrect</span>";
if (isUppercase(password)) {
errorMessage += "<span class=\"failure\"><br>Check Caps lock is not on.</span>";
}
}

} catch(InvalidParameterException ivpex){
app.setErrorMessage(ivpex.getMessage());
} catch(java.net.UnknownHostException uhex){
app.setErrorMessage(uhex.getMessage());
} catch(java.io.IOException ioex){
app.setErrorMessage(ioex.getMessage());
} catch(RadiusException rex){
app.setErrorMessage(rex.getMessage());
}

}
else {
errorMessage = "<span class=\"failure\">Please enter both user name & password.</span>";
}
password = "";
return nextPage;
}

//Authenticate against the RADIUS server
public static boolean authenticate(RadiusClient rc, String userPass, byte[] callingStationId) throws InvalidParameterException, java.net.UnknownHostException, java.io.IOException, RadiusException
{
int returnCode;
returnCode = rc.authenticate(userPass);


        boolean returned = false;

        switch (returnCode){
        case RadiusClient.ACCESS_ACCEPT:
            System.out.println("Authenticated");
            returned = true;
            break;
        case RadiusClient.ACCESS_REJECT:
            System.out.println("Not Authenticated");
            returned = false;
            break;
        case RadiusClient.ACCESS_CHALLENGE:
            System.out.println(rc.getChallengeMessage());
            break;
        default:
            System.out.println("How the hell did we get here?");
            returned = false;
            break;
        }

        return returned;
    }

	// Returns true is each character entered is in uppercase
   private boolean isUppercase(String password)
   {
        boolean flag = true;
        char[] temp = password.toCharArray();
        char aChar;
        for(int i = 0; i<password.length();i++)
        {
            aChar = temp[i];
            if(Character.isLowerCase(aChar))
            {
                flag = false;
                break;
            }

        }

    return flag;
   }

public void checkRecipient() throws Exception
{
System.out.println("Editing Context at start of checkRecipient : " + ec);
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");
//Get their details from LDAP
//Should only be one entry returned for 1 username
//Use a new Editing Context as we us e a different Adaptor type i.e. JNDI not JDBC, not sure if this is required but added in case it was causing the bug
PersonLDAP person = (PersonLDAP) EOUtilities.objectMatchingKeyAndValue(new EOEditingContext (),"PersonLDAP","uid",userName);
r.setFirstName(person.givenName());
r.setSurname(person.sn());
r.setEmailAddress(userName + "@uow.edu.au");
r.setDateRegistered(new NSTimestamp());
//set the session user to the new instance of recipient
System.out.println("new : " + r.surname() + r.logonIdentifier () + r.editingContext());
save();
}
}
System.out.println("editing Context : " + ec);
((Session)session()).setCurrentUser((Recipient) EOUtilities.localInstanceOfObject(((Session)session ()).defaultEditingContext(),r));
}
catch (java.lang.IllegalArgumentException ex) {
}
catch (Exception e)
{
throw e;
}

}
private void save() throws Exception
{
try {
// ec.lock();
ec.saveChanges();
// ec.unlock();
} catch (Exception exception) {
app.setErrorMessage("Error when trying to add a new recipient. save() menu.java\n");
throw exception;
}
}



}


Owen McKerrow WebMaster, emlab Ph : +61 02 4221 5517 http://emlab.uow.edu.au

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'The test of a first-rate intelligence is the ability to hold two opposed ideas in the mind at the same time and still be able to function.'
-F.Scott Fitzgerald,



On 02/08/2006, at 1:09 PM, Ken Anderson wrote:

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.selectObjectsWithFetchSpec ification(EODatabaseChannel.java:209)
at com.webobjects.eoaccess.EODatabaseContext._objectsWithFetchSpecifica tionEditingContext(EODatabaseContext.java:3205)
at com.webobjects.eoaccess.EODatabaseContext.objectsWithFetchSpecificat ion(EODatabaseContext.java:3346)
at com.webobjects.eocontrol.EOObjectStoreCoordinator.objectsWithFetchSp ecification(EOObjectStoreCoordinator.java:539)
at com.webobjects.eocontrol.EOEditingContext.objectsWithFetchSpecificat ion(EOEditingContext.java:4114)
at com.webobjects.eoaccess.EODatabaseContext.objectsForSourceGlobalID (EODatabaseContext.java:4260)
at com.webobjects.eocontrol.EOObjectStoreCoordinator.objectsForSourceGl obalID(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.completeInitializa tionOfObject(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.includeObjectIntoPropertyWit hKey(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.addObjectToBothSidesOfRelati onshipWithKey(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:
40global-village.net


This email sent to email@hidden

--
Coming sometime... - an introduction to web applications using WebObjects and Xcode http://www.global-village.net/wointro


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: Mysterious EditingContext Swap
      • From: Fabrice Pipart <email@hidden>
References: 
 >Mysterious EditingContext Swap (From: Owen McKerrow <email@hidden>)
 >Re: Mysterious EditingContext Swap (From: Ken Anderson <email@hidden>)
 >Re: Mysterious EditingContext Swap (From: Owen McKerrow <email@hidden>)

  • Prev by Date: Re: Event update ; notice
  • Next by Date: Re: Snapshot error
  • Previous by thread: Re: Mysterious EditingContext Swap
  • Next by thread: Re: Mysterious EditingContext Swap
  • Index(es):
    • Date
    • Thread