You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by "Stefan S. (Jira)" <ji...@apache.org> on 2019/09/23 21:53:00 UTC

[jira] [Created] (CAY-2623) Directive #result: Column descriptor mismatch leads to wrong data row keys and missing mappings

Stefan S. created CAY-2623:
------------------------------

             Summary: Directive #result: Column descriptor mismatch leads to wrong data row keys and missing mappings
                 Key: CAY-2623
                 URL: https://issues.apache.org/jira/browse/CAY-2623
             Project: Cayenne
          Issue Type: Bug
    Affects Versions: 4.1.B2
            Reporter: Stefan S.


According to current documentation, the variant of #result "#result(column javaType alias dataRowKey)" is intended for mapping resulting fields of queries to complex DB path expressions which cannot be modeled as alias of fields due to SQL syntax violations.

Unfortunately such fields are not mapped, because the key within the corresponding DataRow field is not equal to 'dataRowKey'.

Debugging org.apache.cayenne.access.jdbc.RowDescriptorBuilder and org.apache.cayenne.template.directive.Result revealed that the corresponding ColumnDescriptor is not found.

The key issue seems to be in RowDescriptorBuilder.getColumentDescriptor method, in the following line:

if (columnRowKey != null && columnRowKey.equalsIgnoreCase(rowKey)) {
 return columnArray[i];
 }

columnRowKey is actually the data row key BUT rowKey is either the alias or the field name of the column. Per definition for the intended case (see above), they are never equal and hence the ColumnDescriptor is not applied.

 

Changing one of the attributes of the condition with the debugger in a way it returns the right ColumnDescriptor, the eventual resulting data object are correct.

 

I'd propose to add (or replace) a comparison of ColumnDescriptor and Column by column alias and / or column name. I'd prefer using the alias (if available) first, since this is IMHO the purpose of an alias. However, that would require to extend ColumnDescriptor class to hold also the alias of the column and to extend Result to apply the alias value to the ColumnDescriptor.

 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)