Skip to content

Commit

Permalink
Escape entity name in Panache queries
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-bekhta committed Mar 7, 2024
1 parent 387c769 commit a6c0bf1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
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() {
}
}

0 comments on commit a6c0bf1

Please sign in to comment.