Skip to content

detectAlias() in QueryUtils will pick up other tokens that have "from" in them and pick the next alias from there. #2508

Closed
@hedshogg

Description

@hedshogg

In Spring Data JPA 2.6.4 something changed in the alias detection that causes it to sometimes incorrectly determine the alias in a query that uses a cast().

For example:

from User u where (cast(:effectiveFrom as date) is null) OR :effectiveFrom >= u.createdAt

incorrectly identifies the alias to be date when it should be u.

Oddly it doesn't pick up on some other similar uses of cast which it has no trouble with, e.g.

@Test
void detectAliasWithCastCorrectly() {

	assertThat(detectAlias("from User u where (cast(:effective as date) is null) OR :effective >= u.createdAt")).isEqualTo("u");
	assertThat(detectAlias("from User u where (cast(:effectiveDate as date) is null) OR :effectiveDate >= u.createdAt")).isEqualTo("u");
	assertThat(detectAlias("from User u where (cast(:effectiveFrom as date) is null) OR :effectiveFrom >= u.createdAt")).isEqualTo("u");

}

where only the last assertion fails. This is similar in some ways to 2232 although in my case it's with a JPA query rather than a native query.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions