Skip to content
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

SQL containing escape '\' as result of findAllByXXXContaining fails on MySQL 8.0 #3216

Closed
tarepanda1024 opened this issue Oct 30, 2023 · 7 comments
Labels
for: external-project For an external project and not something we can fix

Comments

@tarepanda1024
Copy link

When I using findAllByXXXContaining() , jpa generate sql , and append "escape '' ", this makes sql exec failed.Is this a bug or feature ? How can I avoid this?

image

SpringBootVersion: 3.1.5
SpringDataJpaVersion: 3.1.5
JDK:jdk21
mysql:8.0

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 30, 2023
@quaff
Copy link
Contributor

quaff commented Nov 1, 2023

You should turn off NO_BACKSLASH_ESCAPES at mysql server side.

@tarepanda1024
Copy link
Author

You should turn off NO_BACKSLASH_ESCAPES at mysql server side.

Oh , It works ! Thanks ! Is there any config to turn off this feature in JPA not in mysql?

@quaff
Copy link
Contributor

quaff commented Nov 1, 2023

With my test with MySQL Server 5.7.44, no matter NO_BACKSLASH_ESCAPES enabled or not, spring-data-jpa/hibernate will works fine.
NO_BACKSLASH_ESCAPES enabled then escape '\' will be used.
NO_BACKSLASH_ESCAPES disabled then escape '\\' will be used.

I assume your database is not real mysql but some other database use mysql protocol, If I'm correct you should report bug to its team.

@tarepanda1024
Copy link
Author

With my test with MySQL Server 5.7.44, no matter NO_BACKSLASH_ESCAPES enabled or not, spring-data-jpa/hibernate will works fine. NO_BACKSLASH_ESCAPES enabled then escape '\' will be used. NO_BACKSLASH_ESCAPES disabled then escape '\\' will be used.

I assume your database is not real mysql but some other database use mysql protocol, If I'm correct you should report bug to its team.

I start mysql process in docker.It's real mysql.

image

image

@quaff
Copy link
Contributor

quaff commented Nov 1, 2023

You can test escape '\' with NO_BACKSLASH_ESCAPES mode via mysql cli.

@tarepanda1024
Copy link
Author

tarepanda1024 commented Nov 1, 2023

You can test escape '\' with NO_BACKSLASH_ESCAPES mode via mysql cli.

It's fails.

image

@mp911de mp911de added for: external-project For an external project and not something we can fix and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 1, 2023
@mp911de
Copy link
Member

mp911de commented Nov 1, 2023

LIKE with ESCAPE is a feature to control escaping with Starts/Ends/Contains queries to avoid injection of control characters that would be able to change the nature of the query.

As @quaff already pointed out, this is a configuration setting outside of Spring Data.

@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Nov 1, 2023
@mp911de mp911de changed the title SpringDataJpa3.1.5 auto append "escape '\' " to the generated sql for findAllByXXXContaining SQL containing escape '\' as result of findAllByXXXContaining fails on MySQL 8.0 Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix
Projects
None yet
Development

No branches or pull requests

4 participants