We're updating the issue view to help you get more done. 

Lost update problem if relationships are created and saved independently of their parent objects

Description

If a relationship is created and saved independently of its parent object, subsequently saving the parent can cause the relationship to be lost.

E.g.:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 @Test public void testSaveRelationships() { Lookup country = createCountryLookup("country"); Lookup state1 = createStateLookup("state1"); Lookup state2 = createStateLookup("state2"); LookupRelationship relationship1 = createLookupRelationship("lookupRelationship.countryState", country, state1); LookupRelationship relationship2 = createLookupRelationship("lookupRelationship.countryState", country, state2);; List<IMObject> first = new ArrayList<>(); first.add(country); first.add(relationship1); first.add(state1); getArchetypeService().save(first); List<IMObject> second = new ArrayList<>(); second.add(country); second.add(relationship2); second.add(state2); getArchetypeService().save(second); country = (Lookup) getArchetypeService().get(country.getObjectReference()); assertEquals(2, country.getSourceLookupRelationships().size()); }

The above test, when incorporated in LookupTestCase fails at:

1 assertEquals(2, country.getSourceLookupRelationships().size());

There is actually only 1relationship in the retrieved country instance.
After the call to:

1 getArchetypeService().save(first);

the country instance has no relationships. It needs to be retrieved to see the change.
This is OK, but the subsequent call should fail:

1 getArchetypeService().save(second);

It doesn't because saving the relationships does not force the parent lookup to increment the version.

By and large, relationships aren't created and saved outside of their parent objects, however it is an issue for

Environment

None

Status

Assignee

Tim Anderson

Reporter

Tim Anderson

Labels

None

Components

Affects versions

1.9
1.5
2.0

Priority

Major