Skip to content

Handle LIKE with ESCAPE clause in Hibernate and EclipseLink #2956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

gregturn
Copy link
Contributor

HQL parser currently only handles pure characters. It needs to handle a parameter if it's to support SpEL expressions. This lets us enable three test kits.

And NOW, the EclipseLink extension of those tests...must be disabled just like in 3.0.x.

NOTE: This patch should be candidate for backporting to 3.1.x as that also has the same parser.

@gregturn gregturn requested a review from schauder May 15, 2023 21:22
@gregturn gregturn linked an issue May 15, 2023 that may be closed by this pull request
gregturn added a commit that referenced this pull request May 17, 2023
The HQL parser has to handle parameters in addition to character values in order to support SpEL.

See #2954
Original Pull Request: #2956.
@gregturn gregturn force-pushed the issue/gh-2954 branch 2 times, most recently from 86a69e8 to 12bb259 Compare May 17, 2023 20:53
@gregturn gregturn changed the title Handle ESCAPE clause in HQL parser Handle LIKE with ESCAPE clause in Hibernate and EclipseLink. May 17, 2023
@gregturn
Copy link
Contributor Author

This has the fix for HQL in one commit and the fix for EclipseLink in another commit. We can review them both here. I think we should keep them as separate commits since each commit touches a different part of Spring Data JPA.

@gregturn gregturn linked an issue May 17, 2023 that may be closed by this pull request
gregturn added a commit that referenced this pull request May 17, 2023
Migrate tests to H2 to verify LIKE with ESCAPE works properly on EclipseLink with Spring Data JPA.

See #2955
Original Pull Request: #2956.
@gregturn gregturn requested a review from mp911de May 18, 2023 12:38
@mp911de mp911de self-assigned this May 22, 2023
@@ -554,7 +554,7 @@ dealingWithNullExpression

// https://docs.jboss.org/hibernate/orm/6.1/userguide/html_single/Hibernate_User_Guide.html#hql-like-predicate
stringPatternMatching
: expression NOT? (LIKE | ILIKE) expression (ESCAPE character)?
: expression NOT? (LIKE | ILIKE) expression (ESCAPE expression)?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are replacing expressions with binding parameters. What's the reason to switch to an expression instead of using a binding parameter?

Copy link
Contributor Author

@gregturn gregturn May 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I was picking something that supported both character and parameter, which expression handles quite nicely (in the grammar). However, to really dial it in, I tweaked this line in the revised commit:

stringPatternMatching
    : expression NOT? (LIKE | ILIKE) expression (ESCAPE (character|parameter))?
    ;

And the clause rendering this portion:

if (ctx.ESCAPE() != null) {

	tokens.add(new JpaQueryParsingToken(ctx.ESCAPE()));
	if (ctx.character() != null) {
		tokens.addAll(visit(ctx.character()));
	} else if (ctx.parameter() != null) {
		tokens.addAll(visit(ctx.parameter()));
	}
}

This passes all our tests and makes it clear that we either take a character (as original intended) or we support a parameter via SpEL.

gregturn added 3 commits May 30, 2023 16:43
The HQL parser has to handle parameters in addition to character values in order to support SpEL.

See #2954
Original Pull Request: #2956.
Migrate tests to H2 to verify LIKE with ESCAPE works properly on EclipseLink with Spring Data JPA.

See #2955
Original Pull Request: #2956.
@mp911de mp911de added this to the 3.1.1 (2023.0.1) milestone May 31, 2023
@mp911de mp911de changed the title Handle LIKE with ESCAPE clause in Hibernate and EclipseLink. Handle LIKE with ESCAPE clause in Hibernate and EclipseLink May 31, 2023
@mp911de mp911de added type: regression A regression from a previous release in: query-parser Everything related to parsing JPQL or SQL labels May 31, 2023
mp911de pushed a commit that referenced this pull request May 31, 2023
The HQL parser has to handle parameters in addition to character values in order to support SpEL.

Closes #2954
Original Pull Request: #2956.
mp911de pushed a commit that referenced this pull request May 31, 2023
Migrate tests to H2 to verify LIKE with ESCAPE works properly on EclipseLink with Spring Data JPA.

Resolves #2955
Original Pull Request: #2956.
mp911de pushed a commit that referenced this pull request May 31, 2023
The HQL parser has to handle parameters in addition to character values in order to support SpEL.

Closes #2954
Original Pull Request: #2956.
mp911de pushed a commit that referenced this pull request May 31, 2023
Migrate tests to H2 to verify LIKE with ESCAPE works properly on EclipseLink with Spring Data JPA.

Resolves #2955
Original Pull Request: #2956.
@mp911de
Copy link
Member

mp911de commented May 31, 2023

That's merged and backported now.

@mp911de mp911de closed this May 31, 2023
@mp911de mp911de deleted the issue/gh-2954 branch May 31, 2023 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: query-parser Everything related to parsing JPQL or SQL type: regression A regression from a previous release
Projects
None yet
2 participants