Cayenne
  1. Cayenne
  2. CAY-1557

Vertical inheritance is broken for subclasses with more than one flattened attribute

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.1M3
    • Fix Version/s: 3.0.2, 3.1M3
    • Component/s: Core Library
    • Labels:
      None

      Description

      In vertical inheritance mapping model, children objects with multiple flattened attributes are handled incorrectly while inserting in database. Cayenne is trying to do as many duplicated INSERTs in children tables as number of flattened attributes in subclass. As example, attached testcase fails with next log messages:

      INFO: — transaction started.
      Apr 11, 2011 10:42:25 AM org.apache.cayenne.log.CommonsJdbcEventLogger logQuery
      INFO: INSERT INTO IV_ROOT (DISCRIMINATOR, ID, NAME) VALUES (?, ?, ?)
      Apr 11, 2011 10:42:25 AM org.apache.cayenne.log.CommonsJdbcEventLogger logQueryParameters
      INFO: [bind: 1->DISCRIMINATOR:'IvSub2', 2->ID:203, 3->NAME:'XyZX']
      Apr 11, 2011 10:42:25 AM org.apache.cayenne.log.CommonsJdbcEventLogger logUpdateCount
      INFO: === updated 1 row.
      Apr 11, 2011 10:42:25 AM org.apache.cayenne.log.CommonsJdbcEventLogger logQuery
      INFO: INSERT INTO IV_SUB2 (ID, SUB2_ATTR, SUB2_NAME) VALUES (?, ?, ?)
      Apr 11, 2011 10:42:25 AM org.apache.cayenne.log.CommonsJdbcEventLogger logQueryParameters
      INFO: [bind: 1->ID:203, 2->SUB2_ATTR:NULL, 3->SUB2_NAME:NULL]
      Apr 11, 2011 10:42:25 AM org.apache.cayenne.log.CommonsJdbcEventLogger logUpdateCount
      INFO: === updated 1 row.
      Apr 11, 2011 10:42:25 AM org.apache.cayenne.log.CommonsJdbcEventLogger logQueryParameters
      INFO: [bind: 1->ID:203, 2->SUB2_ATTR:NULL, 3->SUB2_NAME:NULL]
      Apr 11, 2011 10:42:25 AM org.apache.cayenne.log.CommonsJdbcEventLogger logQueryError
      INFO: *** error.
      java.sql.SQLException: Unique constraint violation: SYS_IDX_76 in statement [INSERT INTO IV_SUB2 (ID, SUB2_ATTR, SUB2_NAME) VALUES (?, ?, ?)]
      at org.hsqldb.jdbc.Util.throwError(Unknown Source)
      at org.hsqldb.jdbc.jdbcPreparedStatement.executeUpdate(Unknown Source)
      at org.apache.cayenne.access.jdbc.BatchAction.runAsIndividualQueries(BatchAction.java:205)
      at org.apache.cayenne.access.jdbc.BatchAction.performAction(BatchAction.java:86)
      at org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:87)
      at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:254)
      at org.apache.cayenne.access.DataDomainFlushAction.runQueries(DataDomainFlushAction.java:226)
      at org.apache.cayenne.access.DataDomainFlushAction.flush(DataDomainFlushAction.java:144)
      at org.apache.cayenne.access.DataDomain.onSyncFlush(DataDomain.java:796)
      at org.apache.cayenne.access.DataDomain$2.transform(DataDomain.java:763)
      at org.apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:822)
      at org.apache.cayenne.access.DataDomain.onSyncNoFilters(DataDomain.java:760)
      at org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:966)
      at org.apache.cayenne.access.DataDomain.onSync(DataDomain.java:731)
      at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:811)
      at org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:750)
      at org.apache.cayenne.access.VerticalInheritanceTest.testInsert_Sub2(VerticalInheritanceTest.java:139)
      ...

        Activity

        Hide
        Andrus Adamchik added a comment -

        Applied to 3.1 and 3.0 branches. Thanks for the patch!

        Show
        Andrus Adamchik added a comment - Applied to 3.1 and 3.0 branches. Thanks for the patch!
        Hide
        Andrus Adamchik added a comment -

        Thanks for thorough report and patches. I will try to review them tonight.

        Show
        Andrus Adamchik added a comment - Thanks for thorough report and patches. I will try to review them tonight.
        Hide
        Victor Antonovich added a comment -

        Additional issue was discovered. Commit of object with changes in subclass attributes only doesn't update subclass table in database.
        Updated testcase and proposed patch are attached.

        Show
        Victor Antonovich added a comment - Additional issue was discovered. Commit of object with changes in subclass attributes only doesn't update subclass table in database. Updated testcase and proposed patch are attached.
        Hide
        Victor Antonovich added a comment -

        Testcase and proposed patch are attached.

        Show
        Victor Antonovich added a comment - Testcase and proposed patch are attached.

          People

          • Assignee:
            Unassigned
            Reporter:
            Victor Antonovich
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development