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

PanacheEntityBase.delete(String query, Parameters params) doesn't work with SQL prefix - java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: DELETE #18502

Closed
felipewind opened this issue Jul 7, 2021 · 2 comments · Fixed by #18531
Labels
Milestone

Comments

@felipewind
Copy link
Contributor

Describe the bug

If I pass the SQL DELETE prefix command to the String query of the PanacheEntityBase.delete(String query, Parameters params), I receive the following error:

org.jboss.resteasy.spi.UnhandledException: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: DELETE

Example of String query:

DELETE FROM Product P WHERE userName = :userName AND shoppingName = :shoppingName

If I omit the SQL prefix as below, everything works fine:

userName = :userName AND shoppingName = :shoppingName

Command:

delete(query, Parameters.with("userName", userName).and("shoppingName", shoppingName));

I don't know if this is a bug or I misunderstood the String query parameter.

The find(String query, Parameters params) and update(String query, Parameters params) methods work perfectly with or without the SQL prefix.

Expected behavior

PanacheEntityBase.delete(String query, Parameters params) should work with or without the SQL DELETE prefix.

Actual behavior

PanacheEntityBase.delete(String query, Parameters params) don't work with the SQL DELETE prefix.

To Reproduce

$ git clone https://github.com/felipewind/panache-delete-test
$ ./mvnw quarkus:dev

Access http://localhost:8080/q/swagger-ui.

Here you can test the find(), update() and delete() methods with or without the SQL prefix:

image

Each endpoint has a Query Parameter named useSqlPrefix where you can choose if you will or not use the SQL prefix:

image

Configuration

# Log
%dev.quarkus.log.category."org.acme".level=DEBUG
%dev.quarkus.log.min-level=TRACE

# Database
%dev.quarkus.datasource.db-kind=h2
%dev.quarkus.datasource.jdbc.driver=org.h2.Driver
%dev.quarkus.datasource.jdbc.url=jdbc:h2:mem:test
%dev.quarkus.hibernate-orm.database.generation=drop-and-create
%dev.quarkus.hibernate-orm.sql-load-script=import.sql
%dev.quarkus.hibernate-orm.log.bind-parameters=true
%dev.quarkus.hibernate-orm.log.sql=true

Environment (please complete the following information):

Output of uname -a or ver

inux machine 5.8.0-59-generic #66~20.04.1-Ubuntu SMP Thu Jun 17 11:14:10 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)

Quarkus version or git rev

2.0.1.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: /home/helesto/.m2/wrapper/dists/apache-maven-3.8.1-bin/2l5mhf2pq2clrde7f7qp1rdt5m/apache-maven-3.8.1
Java version: 11.0.11, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.8.0-59-generic", arch: "amd64", family: "unix"

@felipewind felipewind added the kind/bug Something isn't working label Jul 7, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Jul 7, 2021

/cc @FroMage, @Sanne, @gsmet, @loicmathieu, @yrodiere

@FroMage
Copy link
Member

FroMage commented Jul 8, 2021

Thanks for reporting. This was not supported, nor documented. Should be fixed by #18531

@quarkus-bot quarkus-bot bot added this to the 2.1 - main milestone Jul 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants