| Bill,
One definite problem I see here is that you are manipulating the object before inserting it into the editing context. The purpose of the EOEditingContext is to track changes. It can't do that if the object is not inserted.
TblDonor newDonor = new TblDonor();
ec2.insertObject(newDonor);
Do the above together....always. I can't think of any case where you wouldn't insert immediately.
In fact I use:
TblDonor newDonor = (Tbldonor)EOUtilities.createAndInsertInstance(ec2, "TblDonor");
This method ensures that the EO in inserted directly into the editing context before it is committed. The only exception to this rule for me is when creating objects on the client-side of a JavaClient program where EOUtiliities is not available. Then I use the previous method.
On Apr 11, 2006, at 5: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._exceptionWithDatabaseContextInformationAdded(EODatabaseContext.java:4676) at com.webobjects.eoaccess.EODatabaseContext.performChanges(EODatabaseContext.java:6384) at com.webobjects.eocontrol.EOObjectStoreCoordinator.saveChangesInEditingContext(EOObjectStoreCoordinator.java:415) at com.webobjects.eocontrol.EOEditingContext.saveChanges(EOEditingContext.java:3165) at BackDoor.removeNewDonor(BackDoor.java:48) 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(); 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(); tdp.setStrPhoneDescription("myPhnDescription"); tdp.setStrPhoneNumber("555-1212"); tdp.setTblDonorPhoneId(new Integer(2)); ec2.insertObject(newDonor); newDonor.addToTblDonorPhones(tdp); //adds one "phone" entry to donor TblDonorPhone tdp2 = new TblDonorPhone(); tdp2.setStrPhoneDescription("myPhnDescription2"); tdp2.setStrPhoneNumber("555-1213"); tdp2.setTblDonorPhoneId(new Integer(3)); newDonor.addToTblDonorPhones(tdp2); //add another "phone" to same donor record 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. 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, -Bill on 4/11/06 11:50, Chuck Hill at [EMAIL PROTECTED] 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. Help/Unsubscribe/Update your Subscription:
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]