diff --git a/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java b/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java index dfe16b94c..4e2bb80f0 100644 --- a/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java +++ b/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java @@ -144,7 +144,7 @@ public abstract class QueryUtils { builder.append(".*"); builder.append("\\)"); - CONSTRUCTOR_EXPRESSION = compile(builder.toString(), CASE_INSENSITIVE); + CONSTRUCTOR_EXPRESSION = compile(builder.toString(), CASE_INSENSITIVE + DOTALL); } /** diff --git a/src/test/java/org/springframework/data/jpa/repository/query/QueryUtilsUnitTests.java b/src/test/java/org/springframework/data/jpa/repository/query/QueryUtilsUnitTests.java index f0cd00184..939b6fcbe 100644 --- a/src/test/java/org/springframework/data/jpa/repository/query/QueryUtilsUnitTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/query/QueryUtilsUnitTests.java @@ -331,6 +331,27 @@ public class QueryUtilsUnitTests { assertThat(hasConstructorExpression("select distinct new Foo() from Bar b"), is(true)); } + /** + * @see DATAJPA-938 + */ + @Test + public void detectsComplexConstructorExpression() { + + assertThat(hasConstructorExpression("select new foo.bar.Foo(ip.id, ip.name, sum(lp.amount)) " // + + "from Bar lp join lp.investmentProduct ip " // + + "where (lp.toDate is null and lp.fromDate <= :now and lp.fromDate is not null) and lp.accountId = :accountId " // + + "group by ip.id, ip.name, lp.accountId " // + + "order by ip.name ASC"), is(true)); + } + + /** + * @see DATAJPA-938 + */ + @Test + public void detectsConstructorExpressionWithLineBreaks() { + assertThat(hasConstructorExpression("select new foo.bar.FooBar(\na.id) from DtoA a "), is(true)); + } + private static void assertCountQuery(String originalQuery, String countQuery) { assertThat(createCountQueryFor(originalQuery), is(countQuery)); }