Skip to content

Commit 9c89381

Browse files
committed
Add support for JPA 3.2 additions to JPQL.
See #3136.
1 parent 510e2da commit 9c89381

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

spring-data-jpa/src/main/antlr4/org/springframework/data/jpa/repository/query/Jpql.g4

+1
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ string_expression
428428
| aggregate_expression
429429
| case_expression
430430
| function_invocation
431+
| string_expression '||' string_expression
431432
| '(' subquery ')'
432433
;
433434

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

+5
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,11 @@ public List<JpaQueryParsingToken> visitString_expression(JpqlParser.String_expre
15271527
tokens.addAll(visit(ctx.case_expression()));
15281528
} else if (ctx.function_invocation() != null) {
15291529
tokens.addAll(visit(ctx.function_invocation()));
1530+
} else if (ctx.string_expression() != null) {
1531+
1532+
tokens.addAll(visit(ctx.string_expression(0)));
1533+
tokens.add(new JpaQueryParsingToken("||"));
1534+
tokens.addAll(visit(ctx.string_expression(1)));
15301535
} else if (ctx.subquery() != null) {
15311536

15321537
tokens.add(TOKEN_OPEN_PAREN);

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

+10
Original file line numberDiff line numberDiff line change
@@ -1600,4 +1600,14 @@ void newShouldBeLegalAsPartOfAStateFieldPathExpression() {
16001600
ORDER BY j.id
16011601
""");
16021602
}
1603+
1604+
@Test // GH-3136
1605+
void doublePipeShouldBeValidAsAStringConcatOperator() {
1606+
1607+
assertQuery("""
1608+
select e.name || ' ' || e.title
1609+
from Employee e
1610+
""");
1611+
}
1612+
16031613
}

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

+9
Original file line numberDiff line numberDiff line change
@@ -983,4 +983,13 @@ void newShouldBeLegalAsPartOfAStateFieldPathExpression() {
983983
ORDER BY j.id
984984
""");
985985
}
986+
987+
@Test // GH-3136
988+
void doublePipeShouldBeValidAsAStringConcatOperator() {
989+
990+
assertQuery("""
991+
select e.name || ' ' || e.title
992+
from Employee e
993+
""");
994+
}
986995
}

0 commit comments

Comments
 (0)