File tree Expand file tree Collapse file tree 5 files changed +46
-0
lines changed
antlr4/org/springframework/data/jpa/repository/query
java/org/springframework/data/jpa/repository/query
test/java/org/springframework/data/jpa/repository/query Expand file tree Collapse file tree 5 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -685,18 +685,22 @@ subtype
685685
686686collection_valued_field
687687 : identification_variable
688+ | reserved_word
688689 ;
689690
690691single_valued_object_field
691692 : identification_variable
693+ | reserved_word
692694 ;
693695
694696state_field
695697 : identification_variable
698+ | reserved_word
696699 ;
697700
698701collection_value_field
699702 : identification_variable
703+ | reserved_word
700704 ;
701705
702706entity_name
Original file line number Diff line number Diff line change @@ -2108,21 +2108,36 @@ public QueryTokenStream visitSubtype(JpqlParser.SubtypeContext ctx) {
21082108
21092109 @ Override
21102110 public QueryTokenStream visitCollection_valued_field (JpqlParser .Collection_valued_fieldContext ctx ) {
2111+ if (ctx .reserved_word () != null ) {
2112+ return visit (ctx .reserved_word ());
2113+ }
21112114 return visit (ctx .identification_variable ());
21122115 }
21132116
21142117 @ Override
21152118 public QueryTokenStream visitSingle_valued_object_field (JpqlParser .Single_valued_object_fieldContext ctx ) {
2119+
2120+ if (ctx .reserved_word () != null ) {
2121+ return visit (ctx .reserved_word ());
2122+ }
21162123 return visit (ctx .identification_variable ());
21172124 }
21182125
21192126 @ Override
21202127 public QueryTokenStream visitState_field (JpqlParser .State_fieldContext ctx ) {
2128+
2129+ if (ctx .reserved_word () != null ) {
2130+ return visit (ctx .reserved_word ());
2131+ }
21212132 return visit (ctx .identification_variable ());
21222133 }
21232134
21242135 @ Override
21252136 public QueryTokenStream visitCollection_value_field (JpqlParser .Collection_value_fieldContext ctx ) {
2137+
2138+ if (ctx .reserved_word () != null ) {
2139+ return visit (ctx .reserved_word ());
2140+ }
21262141 return visit (ctx .identification_variable ());
21272142 }
21282143
Original file line number Diff line number Diff line change @@ -1040,4 +1040,13 @@ void lateralShouldBeAValidParameter() {
10401040 assertQuery ("select e from Employee e where e.lateral = :_lateral" );
10411041 assertQuery ("select te from TestEntity te where te.lateral = :lateral" );
10421042 }
1043+
1044+ @ Test
1045+ void reservedWordsShouldWork () {
1046+
1047+ assertQuery ("select ie from ItemExample ie left join ie.object io where io.externalId = :externalId" );
1048+ assertQuery ("select ie.object from ItemExample ie left join ie.object io where io.externalId = :externalId" );
1049+ assertQuery ("select ie from ItemExample ie left join ie.object io where io.object = :externalId" );
1050+ assertQuery ("select ie from ItemExample ie where ie.status = com.app.domain.object.Status.UP" );
1051+ }
10431052}
Original file line number Diff line number Diff line change @@ -1923,4 +1923,13 @@ void entityNameWithPackageContainingReservedWord(String reservedWord) {
19231923 String source = "select new com.company.%s.thing.stuff.ClassName(e.id) from Experience e" .formatted (reservedWord );
19241924 assertQuery (source );
19251925 }
1926+
1927+ @ Test
1928+ void reservedWordsShouldWork () {
1929+
1930+ assertQuery ("select ie from ItemExample ie left join ie.object io where io.externalId = :externalId" );
1931+ assertQuery ("select ie.object from ItemExample ie left join ie.object io where io.externalId = :externalId" );
1932+ assertQuery ("select ie from ItemExample ie left join ie.object io where io.object = :externalId" );
1933+ assertQuery ("select ie from ItemExample ie where ie.status = com.app.domain.object.Status.UP" );
1934+ }
19261935}
Original file line number Diff line number Diff line change @@ -1027,4 +1027,13 @@ void entityNameWithPackageContainingReservedWord(String reservedWord) {
10271027 assertQuery (source );
10281028 }
10291029
1030+ @ Test
1031+ void reservedWordsShouldWork () {
1032+
1033+ assertQuery ("select ie from ItemExample ie left join ie.object io where io.externalId = :externalId" );
1034+ assertQuery ("select ie.object from ItemExample ie left join ie.object io where io.externalId = :externalId" );
1035+ assertQuery ("select ie from ItemExample ie left join ie.object io where io.object = :externalId" );
1036+ assertQuery ("select ie from ItemExample ie where ie.status = com.app.domain.object.Status.UP" );
1037+ }
1038+
10301039}
You can’t perform that action at this time.
0 commit comments