Skip to content

Order by wrongly added to a native query #2620

@michal-trnka

Description

@michal-trnka

Hello,
I have found an issue in 2.7.1 with adding order by by sort to a query that already has order by.
It happens only in specific scenarios/combinations of the clauses. See the test method bellow.

@Test
void testOrderBy(){
    Sort sort = Sort.by(Sort.Order.desc("age"));

    //works
    assertThat(QueryUtils.applySorting("SELECT * FROM t \n" //
            + "WHERE true \n"
            + "ORDER BY (case when t.id in :priorityIds then 1 else 2 end)\n" //
            + "", sort))
            .endsWith("ORDER BY (case when t.id in :priorityIds then 1 else 2 end)\n" + ", age desc");

    //works
    assertThat(QueryUtils.applySorting("SELECT * FROM t \n" //
            + "WHERE (true OR false) \n"
            + "ORDER BY t.id\n" //
            + "", sort))
            .endsWith("ORDER BY t.id\n" + ", age desc");

    //not working
    assertThat(QueryUtils.applySorting("SELECT * FROM t \n" //
            + "WHERE (true OR false) \n"
            + "ORDER BY (case when t.id in :priorityIds then 1 else 2 end)\n" //
            + "", sort))
            .endsWith("ORDER BY (case when t.id in :priorityIds then 1 else 2 end)\n" + ", age desc");

}

It seems to be related to this change of the regex pattern: 6fd829c .

The issue is not present in 2.7.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions