Skip to content

Commit 05a17f0

Browse files
jewoodevmp911de
authored andcommitted
Fix parsing of single-character string literals in JPQL and EQL collection member expressions.
Signed-off-by: jewoodev <jewoos15@naver.com> Closes #4278 Original pull request: #4282
1 parent fe0886f commit 05a17f0

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 the original author or authors.
2+
* Copyright 2023-present the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@ grammar Eql;
2323
* @see https://eclipse.dev/eclipselink/documentation/3.0/jpa/extensions/jpql.htm
2424
* @author Greg Turnquist
2525
* @author Christoph Strobl
26+
* @author Jewoo Shin
2627
* @since 3.2
2728
*/
2829
}
@@ -677,6 +678,7 @@ constructor_name
677678

678679
literal
679680
: STRINGLITERAL
681+
| CHARACTER
680682
| JAVASTRINGLITERAL
681683
| INTLITERAL
682684
| FLOATLITERAL

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2023 the original author or authors.
2+
* Copyright 2011-present the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@ grammar Jpql;
2424
* @see https://github.com/jakartaee/persistence/blob/master/spec/src/main/asciidoc/ch04-query-language.adoc#bnf
2525
* @author Greg Turnquist
2626
* @author Christoph Strobl
27+
* @author Jewoo Shin
2728
* @since 3.1
2829
*/
2930
}
@@ -670,6 +671,7 @@ constructor_name
670671

671672
literal
672673
: STRINGLITERAL
674+
| CHARACTER
673675
| JAVASTRINGLITERAL
674676
| INTLITERAL
675677
| FLOATLITERAL

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,22 @@ void specialOperators() {
250250
assertQuery("SELECT p FROM Phone p WHERE FUNCTION('TO_NUMBER', p.areaCode) > 613");
251251
}
252252

253+
@Test // GH-4278
254+
void singleCharacterLiteralAsCollectionMemberExpression() {
255+
256+
assertQuery("SELECT e FROM Employee e WHERE 'c' MEMBER OF e.responsibilities");
257+
assertQuery("SELECT e FROM Employee e WHERE 'c' NOT MEMBER OF e.responsibilities");
258+
259+
assertQuery("""
260+
SELECT e
261+
FROM Employee e
262+
WHERE EXISTS (SELECT p FROM Person p WHERE 'c' MEMBER OF p.nicknames)
263+
""");
264+
265+
assertQuery("UPDATE Employee e SET e.name = 'x' WHERE 'c' MEMBER OF e.responsibilities");
266+
assertQuery("DELETE FROM Employee e WHERE 'c' MEMBER OF e.responsibilities");
267+
}
268+
253269
@Test // GH-3314
254270
void isNullAndIsNotNull() {
255271

0 commit comments

Comments
 (0)