Jadon Hansell created CAY-2838: ---------------------------------- Summary: Vertical Inheritance: Problem setting db attribute to null via flattened path Key: CAY-2838 URL: https://issues.apache.org/jira/browse/CAY-2838 Project: Cayenne Issue Type: Bug Affects Versions: 4.2 Environment: Cayenne 4.2, Java 17, MacOS 14 Reporter: Jadon Hansell Attachments: NullifyFlattenedTests.patch
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. -- This message was sent by Atlassian Jira (v8.20.10#820010)