Re: best practices when deleting
Re: best practices when deleting
- Subject: Re: best practices when deleting
- From: Chuck Hill <email@hidden>
- Date: Tue, 11 Apr 2006 14:46:15 -0700
To expand on Ken's answer:
On Apr 11, 2006, at 2:16 PM, WebObjects wrote:
Chuck (and many regarded others),
First, the error:
[2006-04-11 13:57:20 PDT] <WorkerThread0>
com.webobjects.eoaccess.EOGeneralAdaptorException:
deleteRowDescribedByQualifierEntity --
com.webobjects.jdbcadaptor.JDBCChannel: method failed to delete row
in database
at
com.webobjects.eoaccess.EODatabaseContext._exceptionWithDatabaseContex
tInformationAdded(EODatabaseContext.java:4676)
at com.webobjects.eoaccess.EODatabaseContext.performChanges
(EODatabaseContext.java:6384)
at
com.webobjects.eocontrol.EOObjectStoreCoordinator.saveChangesInEditing
Context(EOObjectStoreCoordinator.java:415)
at com.webobjects.eocontrol.EOEditingContext.saveChanges
(EOEditingContext.java:3165)
at BackDoor.removeNewDonor(BackDoor.java:48)
This means that the where clause in the SQL DELETE statement did not
match any rows in the database. In this particular case as you have
confused EOF a great deal.
My code isn’t complex, in fact it all happens in a test component
that simply does the following:
#1 – call a method to create and insert a new ‘donor’ into my
database:
public WOComponent makeNewDonor()
{
EOEditingContext ec2 = this.session().defaultEditingContext();
TblDonor newDonor = new TblDonor();
Change to
TblDonor newDonor = (TblDonor)
EOUtilities.createAndInsertInstance(ec2, "TblDonor");
newDonor.setStrMiddleName("MNameFake");
newDonor.setStrStateOfBirth("Penna.");
newDonor.setStrLastName("LNameFake");
newDonor.setIntGender(new Integer(11));
newDonor.setStrFirstName("FNameFake");
newDonor.setStrSsn("200785252");
newDonor.setStrZip("99999");
newDonor.setStrMemo("this is memo text");
newDonor.setStrAddr2("addr2 fake");
newDonor.setStrAddr1("addr1 fake");
newDonor.setStrState("TN");
newDonor.setStrCity("Memphis");
newDonor.setIntMaritalStatus(new Integer(12));
TblDonorPhone tdp = new TblDonorPhone();
Change to
TblDonorPhone tdp = (TblDonorPhone)
EOUtilities.createAndInsertInstance(ec2, "TblDonorPhone");
tdp.setStrPhoneDescription("myPhnDescription");
tdp.setStrPhoneNumber("555-1212");
tdp.setTblDonorPhoneId(new Integer(2));
Remove this:
ec2.insertObject(newDonor);
newDonor.addToTblDonorPhones(tdp); //adds one "phone" entry
to donor
Change to
newDonor.addObjectToBothSidesOfRelationshipWithKey(tdp,
"tblDonorPhones"); //adds one "phone" entry to donor
TblDonorPhone tdp2 = new TblDonorPhone();
Change to
TblDonorPhone tdp2 = (TblDonorPhone)
EOUtilities.createAndInsertInstance(ec2, "TblDonorPhone");
tdp2.setStrPhoneDescription("myPhnDescription2");
tdp2.setStrPhoneNumber("555-1213");
tdp2.setTblDonorPhoneId(new Integer(3));
newDonor.addToTblDonorPhones(tdp2); //add another "phone"
to same donor record
Change to
newDonor.addObjectToBothSidesOfRelationshipWithKey(tdp2,
"tblDonorPhones"); //adds one "phone" entry to donor
ec2.saveChanges();
return null;
}
#2 – immediately then I call this method to test the delete (mostly
to test the cascading deletion):
public void removeNewDonor() {
EOEditingContext ec = this.session().defaultEditingContext();
//ec.refreshAllObjects();
aDonor = (TblDonor)EOUtilities.objectMatchingKeyAndValue
(ec, "TblDonor", "strSsn", "200785252");
ec.deleteObject(aDonor);
ec.saveChanges();
}
So, upon firing the removeNewDonor() method I get the
“_exceptionWithDatabaseContextInformationAdded
(EODatabaseContext.java:4676)” error. But, when I un-comment the
“ec.refreshAllObjects();” call I get consistent good results.
Well, you toss away all that EOF knows about your objects and it
builds something back that makes sense to it.
I’m only prototyping my code here – as you can see it’s not elegant
and lots of exception handling needs to be added – but for testing
I want to let the exceptions jump right out.
I DO have Chuck’s book, but must admit it’s a bit over my head
since I still don’t have my black-belt in Java. http://www.global-
village.net/wointro will be my next investment. :)
Thanks in advance for pointing out all my elementary flaws,
Stylistically, TblDonorPhone and TblDonor are freaking ugly names.
There are no Windows untyped resource handles here that need to be
hacked around with naming conventions. DonorPhone and Donor would be
the customary names in WO.
Chuck
on 4/11/06 11:50, Chuck Hill at email@hidden wrote:
> Hi Bill,
>
> On Apr 11, 2006, at 11:19 AM, WebObjects wrote:
>>
>> I’m getting ‘safe’ results when using “ec.refreshAllObjects();”
>> prior to
>> selecting and deleting objects from my database/entities. Without
>> it I get
>> all sorts of problems with context(s) not being in sync.
>>
> I have no idea what sort of problems you are getting. Can you
> elaborate? Stack traces can help.
>
>> Is there another or additional safe practice that I should be
>> observing, to
>> ensure newly added or updated records are free for deletion?
>
> I don't recall ever needing to do something special. I'll guess
that
> you are doing something wrong. Some code examples might help us
> determine what that is.
>
> Chuck
_______________________________________________
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 in 2006 - 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