Re: Child Parent Editing Context
Re: Child Parent Editing Context
- Subject: Re: Child Parent Editing Context
- From: Owen McKerrow <email@hidden>
- Date: Fri, 16 Sep 2005 13:34:23 +1000
See below.....
On 16/09/2005, at 4:05 AM, Chuck Hill wrote:
On Sep 14, 2005, at 3:35 PM, Owen McKerrow wrote:
Hi All,
Sorry I forgot to mention where externalDetails() comes from.
External has a one to one with externalDetails and propagates its
primary key to it. Now my understanding is that if you have a one
to one which propagates its primary key when you make an instance
of one of the objects EOF makes the other one for you, in this
case I make my External object, EOF realizes that it will need an
external details so it creates one.
No, that is not correct as Auturo has pointed out.
Once again my understanding is that it would use the same editing
context as the External Object itself. Do I need to explicitly
register this "auto created" object with the EditingContext ? I
would have though not, as I was even printing out the editing
context of both objects, external and externalDetails, and they
had the same editing context.
it sounds to me like the list on the first page is showing a list
of items in defaultEditingContext() and one in childEditingContext.
When going back to the first page, you need to use
EOUtilities.localnstanceOfObject(defaultEditingContext(), addedEO)
to get an EO that you can add to the list.
Thats exactly it. What I was wondering is if I have registered my
second editing context as a child of the default one, create my
objects in this new editing context, commit its changes, should it
not pass these changes back up to its parent ? Or does that not
include passing the new object back up but only changes to objects
which already exist in the parent ?
Thanks
Owen
Chuck
On 14/09/2005, at 6:31 PM, Wolfram Stebel wrote:
Am 14.09.2005 8:40 Uhr schrieb "Owen McKerrow" unter
<email@hidden>:
Hi All,
Hi too,
normaly this error comes, when one of the associated objects is
not in the
same ec, so this seems to me, that in
try {
createdPerson.externalDetails().validateForSave();
} catch (NSValidation.ValidationException exception) {
validationDic.setObjectForKey
(Boolean.TRUE,"saveValidationFailed");
validationDic.setObjectForKey(exception.getMessage
(),"saveValidationString");
}
there is externalDetails().validateForSave(), where
externalDetails() seems
to be another object...
Do you use any setters assigning other objects actually not shown
in your
initatenewExternalPerson?
Wolfram
This is a question that comes from my lack of understanding how a
parent child editing context works. Well I think thats the cause :)
I have a page which allows some to add a new external member to the
site if they aren't already listed. So they click the "Add new
external member button." I create a new member in a child editing
context of the current editing context ( so if they cancel I can
just
forget about it), they fill in the details and hit the save
button, I
then return them to the page they were one and the new person now
becomes available to be selected from the pop-up list of external
members.
The code for making a new person :
public void initatenewExternalPerson()
{
EOEditingContext editCon = new EOEditingContext(ec); //
Where
ec is the default editing context
createdPerson = (External)
EOUtilities.createAndInsertInstance
(editCon,"External");
PersonName newName = (PersonName)
EOUtilities.createAndInsertInstance(editCon,"PersonName");
createdPerson().addObjectToBothSidesOfRelationshipWithKey
(newName,"personNames");
checkingExternalExists = false;
}
The code for the save :
public WOComponent saveNewExternalPerson()
{
//Probably some over kill here on all the validation stuff
but I
wanted to make sure this wasn't the problem.
try {
createdPerson.validateForSave();
} catch (NSValidation.ValidationException exception) {
validationDic.setObjectForKey
(Boolean.TRUE,"saveValidationFailed");
validationDic.setObjectForKey(exception.getMessage
(),"saveValidationString");
}
try {
createdPerson.externalDetails().validateForSave();
} catch (NSValidation.ValidationException exception) {
validationDic.setObjectForKey
(Boolean.TRUE,"saveValidationFailed");
validationDic.setObjectForKey(exception.getMessage
(),"saveValidationString");
}
try {
createdPerson.activeName().validateForSave();
} catch (NSValidation.ValidationException exception) {
validationDic.setObjectForKey
(Boolean.TRUE,"saveValidationFailed");
validationDic.setObjectForKey(exception.getMessage
(),"saveValidationString");
}
if ( validationDic.count() == 0 ) {
createdPerson.editingContext().saveChanges();
}
return context().page();
}
Which must be working as the person appears in the pop-up list as I
wanted them to, but as its only a child editing context it only
registers the object with eparent it doesn't save these changes to
the database ( at least thats my understanding after reading Chucks
book ).
However when I then click on the main save button, I get the
following error :
Error:
java.lang.IllegalStateException: Cannot obtain globalId for an
object
which is registered in an other than the databaseContext's active
editingContext, object: {values = {accessLevel = -1; filePath = ;
onPayroll = 0; publications = (); staffNumber = ; brandNewRecord
= 0;
publicationsEditorOf = (); jchiefGrants = (); toBeShown = 1; title
= ; groupsCoOrdinates = (); email = ; jotherGrants = ();
academicGeneral = ; fileName = ; publicationsAuthorOf = (); url = ;
personNames = (">"); groupMembers = (); hasFile = 0;
externalDetails
= ">"; institution = ; type = 4; }; this = ">"; }, databaseContext:
com.webobjects.eoaccess.EODatabaseContext@487471, object's
editingContext: com.webobjects.eocontrol.EOEditingContext@ecea5e,
databaseContext's active editingContext:
com.webobjects.eocontrol.EOEditingContext@f46941
Reason:
Cannot obtain globalId for an object which is registered in an
other
than the databaseContext's active editingContext, object: {values =
{accessLevel = -1; filePath =
<com.webobjects.foundation.NSKeyValueCoding$Null>; onPayroll = 0;
publications = (); staffNumber =
<com.webobjects.foundation.NSKeyValueCoding$Null>; brandNewRecord =
0; publicationsEditorOf = (); jchiefGrants = (); toBeShown = 1;
title
= <com.webobjects.foundation.NSKeyValueCoding$Null>;
groupsCoOrdinates = (); email =
<com.webobjects.foundation.NSKeyValueCoding$Null>; jotherGrants
= ();
academicGeneral = <com.webobjects.foundation.NSKeyValueCoding
$Null>;
fileName = <com.webobjects.foundation.NSKeyValueCoding$Null>;
publicationsAuthorOf = (); url =
<com.webobjects.foundation.NSKeyValueCoding$Null>; personNames =
("<PersonName dd08eb <EOTemporaryGlobalID: 0 0 -126 -126 72 73 0
0 -6
79 3 0 0 0 1 6 83 75 92 -121 13 -113 120 -104>>"); groupMembers
= ();
hasFile = 0; externalDetails = "<ExternalDetails 8c53f9
<EOTemporaryGlobalID: 0 0 -126 -126 72 73 0 0 -6 79 2 0 0 0 1 6
83 75
92 -121 13 -113 120 -104>>"; institution =
<com.webobjects.foundation.NSKeyValueCoding$Null>; type = 4; };
this
= "<External cb03c4 <EOTemporaryGlobalID: 0 0 -126 -126 72 73 0
0 -6
79 1 0 0 0 1 6 83 75 92 -121 13 -113 120 -104>>"; },
databaseContext:
com.webobjects.eoaccess.EODatabaseContext@487471, object's
editingContext: com.webobjects.eocontrol.EOEditingContext@ecea5e,
databaseContext's active editingContext:
com.webobjects.eocontrol.EOEditingContext@f46941
So its saying that it can't save my new person object as its
registered in another editing context. Which I guess is true it was
created in the child context, but I would have thought this would
have worked, so that is I had saved the child editing context which
then passes its changes up to the parent, save the parent,
passes the
changes onto the DB. But this doesn't seem to be the case.
Have I done something wrong or is my understanding flawed.
Thanks Very Much
Owen McKerrow
WebMaster, emlab
http://emlab.uow.edu.au
Owen McKerrow
WebMaster, emlab
http://emlab.uow.edu.au
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - -
"I like the way this project has somehow, against all common
sense, got itself made."
- Peter Jackson, "The Lord of The Rings"
_______________________________________________
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
--
Practical WebObjects - a book for intermediate WebObjects
developers who want to increase their overall knowledge of
WebObjects, or those who are trying to solve specific application
development problems.
http://www.global-village.net/products/practical_webobjects
Owen McKerrow
WebMaster, emlab
http://emlab.uow.edu.au
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - -
People who prefer typing to pointing then seem to prefer acronyms to
save typing :-)
-Denis Stanton, On people using Command Line Interfaces
_______________________________________________
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