Skip to content

Commit 0671ca2

Browse files
pranav-hsgchristophstrobl
authored andcommitted
Fix count query creation for simple select.
Closes: #3324 Original Pull Request: #3325
1 parent 94e2881 commit 0671ca2

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
* @author Vladislav Yukharin
8282
* @author Chris Fraser
8383
* @author Donghun Shin
84+
* @author Pranav HS
8485
*/
8586
public abstract class QueryUtils {
8687

@@ -156,7 +157,7 @@ public abstract class QueryUtils {
156157
builder.append("\\s*");
157158
builder.append("(select\\s+((distinct)?((?s).+?)?)\\s+)?(from\\s+");
158159
builder.append(IDENTIFIER);
159-
builder.append("(?:\\s+as)?\\s+)");
160+
builder.append("(?:\\s+as)?\\s*)");
160161
builder.append(IDENTIFIER_GROUP);
161162
builder.append("(.*)");
162163

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/QueryUtilsUnitTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
* @author Chris Fraser
5050
* @author Michał Pachucki
5151
* @author Erik Pellizzon
52+
* @author Pranav HS
5253
*/
5354
class QueryUtilsUnitTests {
5455

@@ -934,4 +935,10 @@ select q.specialist_id, listagg(q.points, '%s') as points
934935
where name like :name
935936
""", arg))).containsExactly("points");
936937
}
938+
939+
@Test // GH-3324
940+
void createCountQueryForSimpleQuery(){
941+
String originalQuery = "select * from User";
942+
assertCountQuery(originalQuery,"select count(*) from User");
943+
}
937944
}

0 commit comments

Comments
 (0)