Re: Debuging WOManyToManyRelationship
Re: Debuging WOManyToManyRelationship
- Subject: Re: Debuging WOManyToManyRelationship
- From: Dev WO <email@hidden>
- Date: Sat, 23 Jul 2005 13:09:54 +0200
Hi Chuck, and sorry I realized only this morning you gave more
pointers than the first sentence;)
Hi Xavier,
First off, the source code to WOToManyRelationship is on your
drive. See
/Developer/Examples/JavaWebObjects/Source/JavaWOExtensions/
WOToManyRelationship.java
I saw that in your post to Amedeo;)
On Jul 22, 2005, at 11:27 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.
I finally realize that, but how do I insert the first one, when
the component is first generated?
I've got
productGeneric = new ProductGeneric();
in the component constructor, do I have to do something else to
insert the object in the EC?
What is the ec? The session().defaultEditingContext()? IMHO the
best way to create most EO object (I'm sure there must be
exceptions, but I can't think of them) is to use:
productGeneric = (ProductGeneric)
EOUtilities.createAndInsertInstance(ec, "ProductGeneric");
The ec is session().defaultEditingContext().
I tried to use productGenreic = (ProductGeneric)EOUtilities.create...
and now it works but I have 2 objects inserted in the datastore when
first adding an object...one of them (which is inserted just before)
is mostly NULL... this drives me crazy:(
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.
I've got multiple awakeFromInsertionXXX method in this component
as there's multiple object that can be added/edited in this
component (hidden by conditionals and an internal menu). If I use
ec.insertObject(productGeneric) instead, I have the feeling I'll
get some trouble with other object... am I wrong?
That should not cause a problem.
or should I try to "detect" what kind of object I'm manipulating
(productGeneric, productCustom1, ect)?
Your awakeFromInsertionProductGeneric method is fine, I just
sleepily mistook it for productGeneric.awakeFromInsertion(ec);
OK so I shouldn't change this method. I don't call
super.awakeFromInsertion(ec); in this method, because when I tried it
it wouldn't compile...
Chuck
}
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.
the awakeFromInsertionXXX method is really simple, it just checks
if the item has a datePosted, if it's not the case, he's applying
one, and if it's the case, it applies an dateUpdated.
Only one person is going to edit/add stuff in there, so I "think"
I don't have the need for something complex if I can do it "the
simple way"... or should I say that I'm running out of time for
this psecific component as my customer must be able to fill the
database in a couple of hours:(
Sorry, my bad. I had just gotten out of bed and did not read past
"awakeFromInsertion" to see that this was a custom method of yours
and not the EOEnterpriseObject standard one. I really should drink
more coffee before trying to read e-mail. :-)
No problem Chuck, I am more than thankful for all your help.
Xavier
What you are doing here is OK.
}
productGeneric = new ProductGeneric();
ec.saveChanges();
return context().page();
---
_______________________________________________
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