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

Vertical Inheritance: Problem setting db attribute to null via flattened path

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.2
    • 4.2.1, 5.0-M1
    • Core Library
    • None
    • Cayenne 4.2, Java 17, MacOS 14

    Description

      While using vertical inheritance, I ran into a bug with a non-required attribute on a child DbEntity. The issue occurs when an attribute, accessed via a flattened path like 'child.attr' on the child's ObjEntity, is initially set to a value and then later changed to null. This causes Cayenne to attempt to set the primary key of the child db entity to null as well.

      I've attached a patch that contains failing tests demonstrating this issue on both an ObjEntity's attribute and a belongs-to relationship.

      A temporary workaround I've used is to relocate these columns to the parent DbEntity so the path isn't flattened.

       

      The root of the problem appears to start in the ValuesCreationHandler. During the operation, it runs processFlattenedPath to identify the target row's ID, with add=false. This then iterates through the db path components and invokes processRelationship for each db relationship, again with add=false.

      While processing the first path component, processRelationship creates an UPDATE row operation, attempting to update the child's uuid to its current value (case 2 in the comments). Normally, this would not cause an error. But, because the 'add' parameter is set to false, the ValuePropagationVisitor replaces the current ID with null.

      Attachments

        1. concrete-to-abstract-error.patch
          11 kB
          Jadon Hansell
        2. NullifyFlattenedTests.patch
          2 kB
          Jadon Hansell

        Activity

          People

            ntimofeev Nikita Timofeev
            jhansell Jadon Hansell
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 20m
                20m