[ https://issues.apache.org/jira/browse/CAY-2851?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17841298#comment-17841298 ]
Matt Watson commented on CAY-2851: ---------------------------------- [~ntimofeev] I had only been running the tests on cayenne-server, so I missed testing that one. However, looking at that test, I think it is a bad test. It should have been written with {{assertEquals(5, changeMap.getValue().getUniqueChanges().size());}} instead of {{4}} and then it would have caught this bug that I found. The extra change that shows up with my fix is {{a2}} {{toManyRelationshipChanges}} for {{{}children1{}}}. It used to have a child (\{{ac2}}), but when {{ac2}} was added to {{{}a1{}}}'s children, then it should have been removed from {{{}a2{}}}'s children. Now with my fix that is happening. Let me know what you think about that? > Replace Existing OneToOne From New Object > ----------------------------------------- > > Key: CAY-2851 > URL: https://issues.apache.org/jira/browse/CAY-2851 > Project: Cayenne > Issue Type: Bug > Components: Core Library > Affects Versions: 4.0.3, 4.1.1, 4.2, 5.0-M1 > Reporter: Matt Watson > Assignee: Nikita Timofeev > Priority: Major > Fix For: 4.2.1, 5.0-M1 > > Time Spent: 10m > Remaining Estimate: 0h > > We have a One to One (belongsTo on both sides) relationships between 2 Models > (A & B), very similar to the Painting < - > PaintingInfo in the test > environment. > When we have an existing {{a1}} related to {{b1}} (and vice-versa b1 to a1), > and we create a new b2. Then set {{{}b2.toA = a1{}}}. We find out that > {{b1.toA}} is still related to {{a1}} instead of {{null}} > The closest test that I found is in > {code:java} > CDOOneDep2OneIT.testReplace{code} > but just need to set from the other side of the relationship instead. > I can push up a breaking test soon. Not sure if you prefer it to be on > {{master}} or {{{}STABLE-4.2{}}}. > It seems that during {{b2.setToA(a1)}} the call to {{setToOneTarget("toA", > a1, true)}} triggers a call to {{setReverseRelationship("toA", a1)}} , which > triggers a call to {{{}setToOneTarget("toB", b2, false){}}}. In here it > accesses the {{oldTarget}} which is {{{}b1{}}}. This is where I feel it > should nullify {{b1.toA}} using {{{}unsetReverseRelationship("toB", b1){}}}. > However, it does NOT because {{setReverse}} was passed in as {{{}false{}}}. > Since it does not, at this point if you check the relationships: > {{b2.toA == a1}} _GOOD_ > {{a1.toB == b2}} _GOOD_ > {{b1.toA == a1}} _BAD_ -- This message was sent by Atlassian Jira (v8.20.10#820010)