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

CAST(:param as java.util.UUID) no longer passes validation #3024

Closed
tomas-c opened this issue Jun 14, 2023 · 3 comments
Closed

CAST(:param as java.util.UUID) no longer passes validation #3024

tomas-c opened this issue Jun 14, 2023 · 3 comments
Assignees
Labels
in: query-parser Everything related to parsing JPQL or SQL type: regression A regression from a previous release

Comments

@tomas-c
Copy link

tomas-c commented Jun 14, 2023

If you have a query like this:

@Query("SELECT o FROM Order o WHERE CAST(:userId AS java.util.UUID) IS NULL OR o.user.id = :userId")
fun search(userId: UUID?): List<Order>

Since upgrading to Spring Data JPA 3.1.0, it will throw this exception

Caused by: org.springframework.data.jpa.repository.query.BadJpqlGrammarException: Line 1:48 no viable alternative at input 'CAST(:userIdASjava.'; Bad JPQL grammar [SELECT o FROM Order o WHERE CAST(:userId AS java.util.UUID) IS NULL OR o.user.id = :userId]
	at app//org.springframework.data.jpa.repository.query.BadJpqlGrammarErrorListener.syntaxError(BadJpqlGrammarErrorListener.java:39)
	at app//org.antlr.v4.runtime.ProxyErrorListener.syntaxError(ProxyErrorListener.java:41)
	at app//org.antlr.v4.runtime.Parser.notifyErrorListeners(Parser.java:543)
	at app//org.antlr.v4.runtime.DefaultErrorStrategy.reportNoViableAlternative(DefaultErrorStrategy.java:310)
	at app//org.antlr.v4.runtime.DefaultErrorStrategy.reportError(DefaultErrorStrategy.java:136)
	at app//org.springframework.data.jpa.repository.query.HqlParser.predicate(HqlParser.java:8296)
	at app//org.springframework.data.jpa.repository.query.HqlParser.whereClause(HqlParser.java:3451)
	at app//org.springframework.data.jpa.repository.query.HqlParser.query(HqlParser.java:650)
	at app//org.springframework.data.jpa.repository.query.HqlParser.orderedQuery(HqlParser.java:507)
	at app//org.springframework.data.jpa.repository.query.HqlParser.queryExpression(HqlParser.java:434)
	at app//org.springframework.data.jpa.repository.query.HqlParser.selectStatement(HqlParser.java:380)
	at app//org.springframework.data.jpa.repository.query.HqlParser.ql_statement(HqlParser.java:311)
	at app//org.springframework.data.jpa.repository.query.HqlParser.start(HqlParser.java:250)
	at app//org.springframework.data.jpa.repository.query.HqlQueryParser.parseQuery(HqlQueryParser.java:53)
	at app//org.springframework.data.jpa.repository.query.HqlQueryParser.parse(HqlQueryParser.java:63)
	at app//org.springframework.data.jpa.repository.query.JpaQueryParserSupport$ParseState.lambda$new$0(JpaQueryParserSupport.java:182)
	at app//org.springframework.data.util.Lazy.getNullable(Lazy.java:245)
	at app//org.springframework.data.util.Lazy.get(Lazy.java:114)
	at app//org.springframework.data.jpa.repository.query.JpaQueryParserSupport$ParseState.getContext(JpaQueryParserSupport.java:194)
	at app//org.springframework.data.jpa.repository.query.JpaQueryParserSupport.renderSortedQuery(JpaQueryParserSupport.java:54)

As for why that CAST is needed:-without it Postgres throws org.postgresql.util.PSQLException: ERROR: could not determine data type of parameter $1 when the argument is null due to this issue

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 14, 2023
@tomas-c
Copy link
Author

tomas-c commented Jun 14, 2023

Replacing CAST(:userId AS java.util.UUID) with CAST(:userId AS uuid) makes it work again

@gregturn gregturn self-assigned this Jun 14, 2023
@gregturn gregturn added type: regression A regression from a previous release in: query-parser Everything related to parsing JPQL or SQL and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 14, 2023
@gregturn gregturn added this to the 3.1.1 (2023.0.1) milestone Jun 14, 2023
@gregturn
Copy link
Contributor

This is indeed a regression. I'm glad you found a workaround, but I'll work at mending this to properly support FQDN, since Hibernate itself supports that as well.

gregturn added a commit that referenced this issue Jun 14, 2023
gregturn added a commit that referenced this issue Jun 14, 2023
gregturn added a commit that referenced this issue Jun 14, 2023
@gregturn
Copy link
Contributor

Merged to main and backported to 3.1.x.

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
Development

No branches or pull requests

3 participants