We have three entities BranchLocation, BusinessUnit and BusinessUnitContainsBranchLocations which represents the association between BranchLocations and BusinessUnits.
A BranchLocation can belong to only one BusinessUnit. This is represented by a one-to-one association between BranchLocation and BusinessUnitContainsBranchLocations. This one-to-one association does not share the PK, instead uses the property-ref.
Here is the test scenario:
1. User1 gets Branch1.
2. User2 gets Branch1 and associates it with BusinessUnit1.
3. User1 associates Branch1 with another BusinessUnit2 and saves the original Branch1 which is a detached object. At this point, User1 should get a StaleData error. Instead a Unique Key violation is thrown.
I also see that when User2 saves Branch1 with a new association to BusinessUnit1, the BranchLocation object's version does not get incremented like what you see with one-to-many associations or other property updates.
Attached is a test case to demonstrate the issue.
This is critical since this prevents us from doing stale data checking with one-to-one associations.