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

Escape entity name in Panache queries #39264

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ public static String getCountQueryUsingParser(String query) {

public static String getEntityName(Class<?> entityClass) {
// FIXME: not true?
return entityClass.getName();
// Escape the entity name just in case some keywords are used
// in package names that will prevent ORM from executing a query
return "`%s`".formatted(entityClass.getName());
}

public static String createFindQuery(Class<?> entityClass, String query, int paramCount) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.quarkus.it.panache.fk.issue35812;

import jakarta.persistence.Entity;

import io.quarkus.hibernate.orm.panache.PanacheEntity;

@Entity
public class SomeEntity extends PanacheEntity {
public String string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;

import io.quarkus.it.panache.fk.issue35812.SomeEntity;
import io.quarkus.test.TestTransaction;
import io.quarkus.test.junit.QuarkusTest;

Expand Down Expand Up @@ -39,6 +40,11 @@ public void test3() {
Assertions.assertEquals(0, Beer.find("name", "Lager").count());
}

@Test
public void test4() {
Assertions.assertEquals(0, SomeEntity.findAll().count());
}

void intentionallyNonPrivateHelperMethod() {
}
}
Loading