Skip to content

Subtle behavior change in metamodel with Sort.equals due to the addition of expressions#1496

Open
njr-11 wants to merge 1 commit into
jakartaee:mainfrom
njr-11:fix-breaking-change-to-sort-equals
Open

Subtle behavior change in metamodel with Sort.equals due to the addition of expressions#1496
njr-11 wants to merge 1 commit into
jakartaee:mainfrom
njr-11:fix-breaking-change-to-sort-equals

Conversation

@njr-11

@njr-11 njr-11 commented Jun 22, 2026

Copy link
Copy Markdown
Member

The TCK caught a behavior change where it compares a Sort that has a String entity attribute name to a Sort obtained from the metamodel attribute,

        assertEquals(Sort.ascIgnoreCase(_AsciiChar.HEXADECIMAL),
                     _AsciiChar.hexadecimal.ascIgnoreCase());

Previously, both of these were backed by String values and were equal. However, the latter now also has an expression (in this case, _AsciiChar.hexadecimal) causing .equals to report false. Similarly, .hashCode will now compute different values for the two Sort instances as well.

I would argue the new behavior is better because it means _Product.name.asc() will not equal _Employee.name.asc(). However, in Data 1.0, the two were .equals because there was no expression component and the other components (property="name", isAscending=true, ignoreCase=false) all match.

With respect to Sort itself, there is no breaking change. Sort.asc(_Product.NAME) and Sort.asc(_Employee.NAME) are still .equals. The new behavior only applies when an expression is added, which is new in 1.1. The behavior change is really isolated to Sort obtained from TextAttribute. I think we can address this by continuing to obtain Sort without an expression from TextAttribute when the deprecated TextAttributeRecord is used, and defaulting to Sort backed by the TextAttribute as the expression when the TextAttribute.of method that we introduced in Data 1.1 as the recommended approach is used.

@njr-11 njr-11 added bug Something isn't working test Something test-related labels Jun 22, 2026
@njr-11 njr-11 added this to the 1.1 milestone Jun 22, 2026
@gavinking

Copy link
Copy Markdown
Member

I guess this is OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working test Something test-related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants