diff --git a/extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/CommonPanacheQueryImpl.java b/extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/CommonPanacheQueryImpl.java index 70bfb1a803373..e06891dcb7e20 100644 --- a/extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/CommonPanacheQueryImpl.java +++ b/extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/CommonPanacheQueryImpl.java @@ -54,6 +54,8 @@ public void close() { private Map> filters; + private final String lineSeparator = System.getProperty("line.separator");; + public CommonPanacheQueryImpl(EntityManager em, String query, String orderBy, Object paramsArrayOrMap) { this.em = em; this.query = query; @@ -82,7 +84,7 @@ public CommonPanacheQueryImpl project(Class type) { throw new PanacheQueryException("Unable to perform a projection on a named query"); } - String lowerCasedTrimmedQuery = query.trim().toLowerCase(); + String lowerCasedTrimmedQuery = query.trim().replace(lineSeparator, " ").toLowerCase(); if (lowerCasedTrimmedQuery.startsWith("select new ")) { throw new PanacheQueryException("Unable to perform a projection on a 'select new' query: " + query); } @@ -93,7 +95,7 @@ public CommonPanacheQueryImpl project(Class type) { // New query: SELECT new org.acme.ProjectionClass(e.field1, e.field2) from EntityClass e if (lowerCasedTrimmedQuery.startsWith("select ")) { int endSelect = lowerCasedTrimmedQuery.indexOf(" from "); - String trimmedQuery = query.trim(); + String trimmedQuery = query.trim().replace(lineSeparator, " "); // 7 is the length of "select " String selectClause = trimmedQuery.substring(7, endSelect).trim(); String from = trimmedQuery.substring(endSelect); diff --git a/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/TestEndpoint.java b/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/TestEndpoint.java index 363fd589281d4..e316d5f99c67f 100644 --- a/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/TestEndpoint.java +++ b/integration-tests/hibernate-orm-panache/src/main/java/io/quarkus/it/panache/TestEndpoint.java @@ -1188,6 +1188,11 @@ public String testProjection() { person = Person.find("name = ?1", "2").project(PersonName.class).firstResult(); Assertions.assertEquals("2", person.name); + person = Person.find("select uniqueName, name\nfrom io.quarkus.it.panache.Person\nwhere name = ?1", "2") + .project(PersonName.class) + .firstResult(); + Assertions.assertEquals("2", person.name); + person = Person.find("name = :name", Parameters.with("name", "2")).project(PersonName.class).firstResult(); Assertions.assertEquals("2", person.name);