Re: Debuging WOManyToManyRelationship
Re: Debuging WOManyToManyRelationship
- Subject: Re: Debuging WOManyToManyRelationship
- From: Chuck Hill <email@hidden>
- Date: Fri, 22 Jul 2005 10:58:51 -0700
On Jul 22, 2005, at 10:02 AM, Dev WO wrote:
After digging for hours, I have found something very strange:
If I remove the WOToMany, I can add object to the database, then I
put back the WOToMany, then edit a previous object (already in the
DB) then the WOToMany works, everything gets written in the join
table, no problem...
So I could save all products first then apply them to the
categories (WOToMany), but in fact I can't do that as I got the
crash even if I don't select anything in the WOToMany browser...
So I understand this seems to be related to the object not inside
an EC when it is created. So I tried:
---
public WOComponent addOrUpdateProductGeneric()
{
if (!productGenericList.containsObject(productGeneric))
{
ec.insertObject(productGeneric);
This looks like you are editing an object not yet inserted into the
EC. Apple examples or not, this is bad practice.
productGenericList.addObject(productGeneric);
awakeFromInsertionProductGeneric(ec); // this is to
set the date posted
You should never call this yourself. Calling ec.insertObject
(productGeneric) calls this (unless you have forgotten to call
super.awakeFromInsertion() somewhere.
}
else
{
awakeFromInsertionProductGeneric(ec); // this is to
set the date last updated
definitely a bad thing to do. See the CooperatingEditingContext in
Practical WebObjects for a good way to do this.
}
productGeneric = new ProductGeneric();
ec.saveChanges();
return context().page();
---
But it leads to the same crash...
any ideas?
Thanks
Le 22 juil. 05 à 13:01, Dev WO a écrit :
I've been setting up a form with a WOManyToMany relationship, I
tried it and it worked, the correct values were written in the
database in the join-table.
I still worked on this project, though I don't remember exactly
what I've done...
I had to left this for a couple days and when back on it, I've
seen that saving would lead to an exception like the one Amedeo
Mantica got on may 19th 2005:
----
[2005-07-22 10:24:51 CEST] <WorkerThread7>
java.lang.NullPointerException
at
com.webobjects.woextensions.WOToManyRelationship.updateSourceObject
(WOToManyRelationship.java:348)
at
com.webobjects.woextensions.WOToManyRelationship.setSelections
(WOToManyRelationship.java:421)
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.NSKeyValueCoding$1.setMethodValue
(NSKeyValueCoding.java:688)
at com.webobjects.foundation.NSKeyValueCoding
$_MethodBinding.setValueInObject(NSKeyValueCoding.java:1175)
at com.webobjects.foundation.NSKeyValueCoding
$DefaultImplementation.takeValueForKey(NSKeyValueCoding.java:1293)
at com.webobjects.appserver.WOComponent.takeValueForKey
(WOComponent.java:1550)
at com.webobjects.foundation.NSKeyValueCoding
$Utility.takeValueForKey(NSKeyValueCoding.java:519)
at com.webobjects.foundation.NSValidation
$DefaultImplementation.validateTakeValueForKeyPath
(NSValidation.java:733)
at
com.webobjects.appserver.WOComponent.validateTakeValueForKeyPath
(WOComponent.java:1273)
at
com.webobjects.appserver._private.WOKeyValueAssociation.setValue
(WOKeyValueAssociation.java:71)
at
com.webobjects.appserver._private.WOBrowser._fastTakeValuesFromReques
t(WOBrowser.java:153)
at
com.webobjects.appserver._private.WOBrowser.takeValuesFromRequest
(WOBrowser.java:168)
at
com.webobjects.appserver._private.WODynamicGroup.takeChildrenValuesFr
omRequest(WODynamicGroup.java:81)
at
com.webobjects.appserver._private.WODynamicGroup.takeValuesFromReques
t(WODynamicGroup.java:89)
at
com.webobjects.appserver._private.WOConditional.takeValuesFromRequest
(WOConditional.java:41)
at
com.webobjects.appserver._private.WODynamicGroup.takeChildrenValuesFr
omRequest(WODynamicGroup.java:81)
at
com.webobjects.appserver._private.WODynamicGroup.takeValuesFromReques
t(WODynamicGroup.ja
----
But has the solution was to change the workflow, it doesn't help
me fix my problem...
So let's try to explain it correctly:
-I've got a regular form, and without the WOToMany it works like a
charm.
-When adding the WOToMany, the display is also correct, so the
bindings should be ok (I've rechecked numerous time, and if I made
a mistake I couldn't get a correct display), here's the .woa
declaration:
----
ToManyRelationship: WOToManyRelationship {
relationshipKey = "productCategorys";
sourceObject = productGeneric;
sourceEntityName = "ProductGeneric";
uiStyle = "browser";
destinationDisplayKey = "name";
}
----
-When submitting the form (which also save ec), I got the
crash...Here's my save method:
----
public WOComponent addOrUpdateProductGeneric()
{
if (!productGenericList.containsObject(productGeneric))
{
productGenericList.addObject(productGeneric);
ec.insertObject(productGeneric);
awakeFromInsertionProductGeneric(ec); // this is to
set the date posted
}
else
{
awakeFromInsertionProductGeneric(ec); // this is to
set the date last updated
}
productGeneric = new ProductGeneric();
ec.saveChanges();
return context().page();
}
----
I really don't know how to track what's happening...
If anyone could come up with a clue, that would be a real savior.
Thanks
Xavier
PS: As mentioned by Chuck in an answer to Amedeo's problem:
----
This is where the execption happens, last line:
public void updateSourceObject(NSArray newValues) {
// add new values to relationship, remove old values
Object aSourceObject = _localSourceObject();
boolean isDictionary = (aSourceObject instanceof
NSMutableDictionary);
NSMutableDictionary _dictionary = (isDictionary) ?
(NSMutableDictionary) aSourceObject : null;
EOEnterpriseObject _eo = (!isDictionary) ?
(EOEnterpriseObject) aSourceObject : null;
String masterKey = _localRelationshipKey();
NSMutableArray currentValues = (NSMutableArray)
NSKeyValueCoding.Utility.valueForKey(aSourceObject, masterKey);
int count = currentValues.count();
Thus, NSKeyValueCoding.Utility.valueForKey(aSourceObject,
masterKey) returns null. In other words, sourceObject.valueForKey
(masterKey) returns null. Check the spelling of your bindings.
It looks like you have misspelled the tomany relation.
Chuck
----
I've checked all bindings, and I cannot find a mistake. In
addition to that, Could I get the WOToMany to display if there
were an error?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40anazys.com
This email sent to email@hidden
_______________________________________________
WebObjects-dev mailing list
email@hidden
http://www.omnigroup.com/mailman/listinfo/webobjects-dev
--
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
_______________________________________________
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