EditingContext problem, ghost entry in datastore [ was Debuging WOManyToManyRelationship]
EditingContext problem, ghost entry in datastore [ was Debuging WOManyToManyRelationship]
- Subject: EditingContext problem, ghost entry in datastore [ was Debuging WOManyToManyRelationship]
- From: Dev WO <email@hidden>
- Date: Sat, 23 Jul 2005 16:41:25 +0200
So finally the real problem is the editing context.
What I have is some weird behavior when adding/updating my object:
some extra objects are saved in the datastore!
here's my application constructor:
-----
public ProductsPage(WOContext context) {
super(context);
session = (Session)session();
ec = session.defaultEditingContext();
productGeneric = (ProductGeneric)
EOUtilities.createAndInsertInstance(ec, "ProductGeneric");
productGeneric.setCommentaryAllowed(new Boolean(true));
productGeneric.setIsAvailable(new Boolean(true));
// This is to help me find which object is generated
productGeneric.setSalesPrice(new Integer(52));
}
-----
So if I understand correctly, I'd say that I have a productGeneric
Object which is inserted in the ec (defaultEC), with a couple default
value to be able to "see" where's coming from the ghost object.
In my addOrUpdate method, I have:
-----
public WOComponent addOrUpdateProductGeneric()
{
awakeFromInsertionProductGeneric(ec); //setting the date
posted/updated
if (!productGenericList.containsObject(productGeneric))
{
productGeneric.setStockStatus(new Integer(0));
}
else
{
editMode = false;
}
ec.saveChanges();
productGeneric = new ProductGeneric();
ec.insertObject(productGeneric);
productGeneric.setCommentaryAllowed(new Boolean(true));
productGeneric.setIsAvailable(new Boolean(true));
productGeneric.setSalesPrice(new Integer(0));
return context().page();
}
-----
but if I add a new product, I got another one inserted to the
datastore as well. The ghost comes from the component constructor
(because it has the salesPrice set to 52)...
I most probably do it the wrong way for sure (if not it would work),
but I just can't find where I do it wrong...
The method really look like:
-it gives some extra values to the productGeneric object (like
datePosted trough the custom awakeFromInsertionProductGeneric)
-then save the ec (which should only have this object)
-and finally create an empty productGeneric, insert it in the ec and
set a couple values (which works fine because there's no problem
after the first saving)
Did I read my own code incorrectly? probably but I really can't
figure this out...
any tip that could help me is more than welcome.
Xavier
PS: now I know I have to put the object into and editing context
before manipulating it, but pretty much all the resources I learned
from (Apple's documentation, WebObjects5 book, ...) gave me a bad
habit;)
_______________________________________________
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