• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Trouble Saving to-many relationship
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trouble Saving to-many relationship


  • Subject: Re: Trouble Saving to-many relationship
  • From: Chuck Hill <email@hidden>
  • Date: Wed, 4 Oct 2006 11:10:48 -0700

Hi Anthony,

First, please start a new message for a new topic. Replying to another message messes up the threading shown in many mail clients.


On Oct 3, 2006, at 8:21 PM, Anthony Martello wrote:

I am having trouble saving to the database using a many-to-many relationship that I have set up. I don't know where the problem is. It could be with the EO model or the way I am approaching this scenario. I know that changes are being correctly held in the editing context, they just won't save to the db (Openbase). I know this because if I comment out the saveChanges() line I can view the results on the page (also if the line is uncommented I get the error message but if I use the browser's back button the course is correctly added). See Error below.

I have a many-to-many relationship called courses between the Person table and the Course table through CoursePerson join table. In the code below courseToAssign holds reference to a course object that is already in the Course table and student holds a person object that is already in the person table. I am trying assign an already existing person to an already existing course.

Any help would be greatly appreciated.

Anthony

 public WOComponent assignToCourse()
    {
		courseToAssign = aCourse;
		EOEditingContext ec = session().defaultEditingContext();

The next line is your problem. ec.insertObject is for an EO that (a) has just been created and (b) is not yet in the database. Which is why EOF is complaining, "Cannot insert an object that is already in the database". Remove this line and your code will work:
ec.insertObject(courseToAssign);



Chuck


student.addObjectToBothSidesOfRelationshipWithKey(courseToAssign, "courses");
ec.saveChanges();
return null;
}




Re-enter
Axiom Exception Description
Application: Axiom
Error: java.lang.IllegalStateException: recordInsertForObject: com.webobjects.eoaccess.EODatabaseContext com.webobjects.eoaccess.EODatabaseContext@1067af found a snapshot for EO with Global ID:_EOIntegralKeyGlobalID[Course (java.lang.Integer)1] that has been inserted into com.webobjects.eocontrol.EOEditingContextcom.webobjects.eocontrol.EOEd itingContext@c7e176. Cannot insert an object that is already in the database
Reason: recordInsertForObject: com.webobjects.eoaccess.EODatabaseContext com.webobjects.eoaccess.EODatabaseContext@1067af found a snapshot for EO with Global ID:_EOIntegralKeyGlobalID[Course (java.lang.Integer)1] that has been inserted into com.webobjects.eocontrol.EOEditingContextcom.webobjects.eocontrol.EOEd itingContext@c7e176. Cannot insert an object that is already in the database
Stack trace:
File Line# Method Package
EODatabaseContext.java 4913 recordInsertForObject com.webobjects.eoaccess
EODatabaseContext.java 5858 prepareForSaveWithCoordinator com.webobjects.eoaccess
EOObjectStoreCoordinator.java 409 saveChangesInEditingContext com.webobjects.eocontrol
EOEditingContext.java 3226 saveChanges com.webobjects.eocontrol
assignToCourse.java 53 saveCourseAssignment assignToCourse
NativeMethodAccessorImpl.java NA invoke0 sun.reflect
NativeMethodAccessorImpl.java 39 invoke sun.reflect
DelegatingMethodAccessorImpl.java 25 invoke sun.reflect
Method.java 585 invoke java.lang.reflect
KeyValueCodingProtectedAccessor.java 54 methodValue KeyValueCodingProtectedAccessor
NSKeyValueCoding.java 1160 valueInObject com.webobjects.foundation
NSKeyValueCoding.java 1268 valueForKey com.webobjects.foundation
WOComponent.java 1539 valueForKey com.webobjects.appserver
NSKeyValueCoding.java 498 valueForKey com.webobjects.foundation
NSKeyValueCodingAdditions.java 212 valueForKeyPath com.webobjects.foundation
WOComponent.java 1600 valueForKeyPath com.webobjects.appserver
WOKeyValueAssociation.java 46 valueInComponent com.webobjects.appserver._private
WOSubmitButton.java 70 invokeAction com.webobjects.appserver._private
WODynamicGroup.java 101 invokeChildrenAction com.webobjects.appserver._private
WODynamicGroup.java 110 invokeAction com.webobjects.appserver._private
WOForm.java 82 invokeAction com.webobjects.appserver._private
WODynamicGroup.java 101 invokeChildrenAction com.webobjects.appserver._private
WODynamicGroup.java 110 invokeAction com.webobjects.appserver._private
WOComponent.java 945 invokeAction com.webobjects.appserver
WOSession.java 1168 invokeAction com.webobjects.appserver
WOApplication.java 1375 invokeAction com.webobjects.appserver
WOComponentRequestHandler.java 196 _dispatchWithPreparedPage com.webobjects.appserver._private
WOComponentRequestHandler.java 287 _dispatchWithPreparedSession com.webobjects.appserver._private
WOComponentRequestHandler.java 322 _dispatchWithPreparedApplication com.webobjects.appserver._private
WOComponentRequestHandler.java 358 _handleRequest com.webobjects.appserver._private
WOComponentRequestHandler.java 432 handleRequest com.webobjects.appserver._private
WOApplication.java 1306 dispatchRequest com.webobjects.appserver
WOWorkerThread.java 173 runOnce com.webobjects.appserver._private
WOWorkerThread.java 254 run com.webobjects.appserver._private
Thread.java 613 run java.lang
NA : Non applicable, JIT activated


On Oct 3, 2006, at 12:07 PM, email@hidden
--

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


References: 
 >Re: Webobjects-dev Digest, Vol 3, Issue 693 (From: Anthony Martello <email@hidden>)

  • Prev by Date: Re: Webobjects-dev Digest, Vol 3, Issue 693
  • Next by Date: CSS Table/Row Question
  • Previous by thread: Re: Webobjects-dev Digest, Vol 3, Issue 693
  • Next by thread: CSS Table/Row Question
  • Index(es):
    • Date
    • Thread