Objects never belong to any context other than the one that created them. When you call n = c2.localObject(o), o still exists in the original context c1, but a new n is created for context c2. Unless c1 = c2 in which case o = n.
Note that you need to be careful calling localObject on an object in a state other than committed or hollow. On Fri, Mar 4, 2016 at 11:00 AM, Andrew Willerding <[email protected]> wrote: > Thank you [email protected]. Without your help I would never have found a > solution. > > Of course my code was generating the duplicate entry! Sorry to have bugged > the list on this last error. > > I'm not sure I understand why different objects must be "localized" with the > localObject method vs the setObjectContext. From my limited understanding > of the inner workings of Cayenne, the setObjectContext should have worked. > I have used the setObjectContext with success (I think - in the error went > away) in other situations when I get an error suggesting that one object is > not in the context of another object > > > > > On 03/03/16 03:37 PM, Andrew Willerding wrote: >> >> I had to add newItem before the getObjectContext() to allow the program to >> compile and then unfortunately I'm getting the error below. There shouldn't >> be any duplicate entries as this is the first record I'm attempting to >> insert for this particular project and contact. The underlying project id >> is 9999 and the contact id is 1922 so I'm not sure what is generating the >> duplicate entry. >> >
