Uploaded image for project: 'Cayenne'
  1. Cayenne
  2. CAY-1008

Reverse relationships may not be correctly set if inheritance is used.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 3.0
    • None
    • Core Library
    • None

    Description

      Given two entities, Employee and Address, such that there is a one-to-many relationship between the two, it may be possible that reverse relationships are not fully set if inheritance is used.

      For example, let's say that HomeAddress extends Address, then the following fails:

      Employee e = context.newObject(Employee.class);

      Address a = context.newObject(Address.class);
      a.setToEmployee(e);

      assertEquals(1, e.getAddresses().size());
      assertEquals(0, e.getHomeAddresses().size());

      HomeAddress ha = context.newObject(HomeAddress.class);
      ha.setToEmployee(e);

      assertEquals(2, e.getAddresses().size());
      assertEquals(1, e.getHomeAddresses().size());

      The last assertion fails as e.getHomeAddresses() will return an empty list.

      On the face of it, the problem is that the ObjRel "addresses" is being set rather than "homeAddresses". This is due to how ObjRelationship#getReverseRelationship() determines reverse relationships. It does so by inspecting the relationship structure and if there's a match, returns it. "addresses" and "homeAddresses" have the same structure and "addresses" is the first match found and returned.

      Simply reversing order or other similar tricks won't really do anything more for us though. The real issue seems to be how to deal with multiple ObjRels that match to the same DbRel. Each ObjRel does need to be updated in order for the graph to remain consistent.

      Attachments

        Issue Links

          Activity

            People

              andrus Andrus Adamchik
              nirvdrum Kevin Menard
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated: