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

Vertical Inheritance: Cannot Insert Record For Implementing Class with Attribute And Relationship

    Details

      Description

      When using the following DbEntities:

      IV_OTHER (id, name)
      IV_BASE (id, type, name)
      IV_IMPL (id, attr1, other_id) (vertically inherits IV_BASE)

      all fields are non-null

      We end up with ObjEntities:
      IvOther
      IvBase (abstract)
      IvImpl extends IvBase

      When running the following code:

      IvOther other = context.newObject(IvOther.class);
      other.setName("other");
      
      IvImpl impl = context.newObject(IvImpl.class);
      impl.setName("Impl 1");
      impl.setAttr1("attr1");
      impl.setOther(other);
      
      context.commitChanges();
      

      Committing this errors in the database, because its trying to insert into the IV_IMPL table with a NULL value for OTHER_ID

      [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - INSERT INTO IV_OTHER (ID, NAME) VALUES (?, ?)
      [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - [bind: 1->ID:200, 2->NAME:'other']
      [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - === updated 1 row.
      [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - INSERT INTO IV_BASE (ID, NAME, TYPE) VALUES (?, ?, ?)
      [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - [bind: 1->ID:200, 2->NAME:'Impl 1', 3->TYPE:'I']
      [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - === updated 1 row.
      [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - INSERT INTO IV_IMPL (ATTR1, ID, OTHER_ID) VALUES (?, ?, ?)
      [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - [bind: 1->ATTR1:'attr1', 2->ID:200, 3->OTHER_ID:NULL]
      [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - *** error.
      java.sql.SQLException: Attempt to insert null into a non-nullable column: column: OTHER_ID table: IV_IMPL in statement [INSERT INTO IV_IMPL (ATTR1, ID, OTHER_ID) VALUES (?, ?, ?)]
      

      If there was only an attribute in IV_IMPL, or only a relationship on IV_IMPL it would work fine. But the DataDomainFlushAction is using separate InsertBatchQuery to handle the attributes and another one to handle the relationships.

      I have not yet figured out how to solve, but will continue to look into it.

        Attachments

        1. CAY-2122-test-with-fix.patch
          19 kB
          Matt Watson
        2. CAY-2122-test.patch
          12 kB
          Matt Watson

          Issue Links

            Activity

              People

              • Assignee:
                andrus Andrus Adamchik
                Reporter:
                mattraydub Matt Watson
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: