• 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
Many-to-many relationship bug
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Many-to-many relationship bug


  • Subject: Many-to-many relationship bug
  • From: Nick Pilch <email@hidden>
  • Date: Tue, 7 Jan 2003 16:45:53 -0800

I have come across a bug that is present in both WO 5.1.4 and 5.2. This bug did not exist in 4.51. I came across this in some production code, however I created a small project and associated OpenBase database to demonstrate the problem. Here is a description of what happens.

I have 2 entities joined by another entity with many-to-many relationships. The 2 entities have compound primary keys and the primary key of the join entity is also compound, formed from one-half of the primary key of each of the two main entities.

SurveyCollection <<===>> JoinEntity <<===>> Survey

Please refer to the screenshot of the model at http://homepage.mac.com/npilch/.Pictures/model.jpg. The model itself is accessible from http://homepage.mac.com/npilch, for the more curious.

Note that the relationships *to* the JoinEntity are marked as "propagate primary key"

When I try to create a JoinEntity and populate its PKs by using addObjectToBothSidesOfRelationshipWithKey(aSurveyCollection, "surveyCollections") and addObjectToBothSidesOfRelationshipWithKey(aSurvey, "surveys"), I get an exception like the following:

java.lang.IllegalStateException: Server exception: cannot update primary-key 'surveyID' from '1' to '<com.webobjects.foundation.NSKeyValueCoding$Null>' on object:{values = {revisionNumber = 1; joins = ("<com.webobjects.eocontrol.EOGenericRecord dd706 <EOTemporaryGlobalID: 0 0 -57 108 74 71 1 0 4 87 1 0 0 0 0 -14 -102 -107 -118 -119 -1 66 104 -128>>"); PK1 = 1; }; this = "<com.webobjects.eocontrol.EOGenericRecord 3c0144 _EOVectorKeyGlobalID[Survey (java.lang.Integer)1,(java.lang.Integer)1]>"; } of entity: Survey in databaseContext com.webobjects.eoaccess.EODatabaseContext@532a0a

WO seems to want to null out surveyID from Survey. This is the exact opposite of what I would expect. It seems like WO is propogating the null value of surveyID in the join object to the valid surveyID of the Survey object. Instead, surveyID of JoinEntity should be populated with surveyID of Survey.


Upon further work, I discovered that joining an *existing* JoinEntity object resulted in similar behavior. WO would try to set the surveyID of Survey (to its current value, not null in this case) and then throw an exception because, again, a primary key is being modified!



I can work around the first instance of the bug by making the primary keys of JoinEntity class properties and setting them directly, but adding an existing JoinEntity object still poses a problem for which I don't yet have a work-around.



I have already submitted this bug to Apple. I thought the lists might like to know about this and offer any advice.



(Please note that changing the DB schema is a remote possibility. I inherited this schema and would probably not have chosen to model the data this way...)
--


Nick Pilch / email@hidden
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Many-to-many relationship bug
      • From: Art Isbell <email@hidden>
  • Prev by Date: Re: Converting an EO to a String
  • Next by Date: Re: Many-to-many relationship bug
  • Previous by thread: JSModalWindow
  • Next by thread: Re: Many-to-many relationship bug
  • Index(es):
    • Date
    • Thread