Skip to content

Commit 514faca

Browse files
committed
JPQL parser must support LEFT, INNER, and OUTER as possible identifiers.
1 parent 14c3881 commit 514faca

File tree

2 files changed

+121
-3
lines changed

2 files changed

+121
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,9 +596,12 @@ trim_character
596596

597597
identification_variable
598598
: IDENTIFICATION_VARIABLE
599-
| ORDER // Gap in the spec requires supporting 'Order' as an entity name
600-
| COUNT // Gap in the spec requires supporting 'count' as a possible name
601-
| KEY // Gap in the sepc requires supported 'key' as a possible name
599+
| ORDER
600+
| COUNT
601+
| KEY
602+
| LEFT
603+
| INNER
604+
| OUTER
602605
| spel_expression // we use various SpEL expressions in our queries
603606
;
604607

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

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,121 @@ void orderByShouldWorkWithSubSelectStatements() {
674674
+ "GROUP BY i2.field.id, i2.version)", sort)).endsWith("order by i.age desc");
675675
}
676676

677+
@Test // GH-2864
678+
void usingRightAsARelationshipNameShouldWork() {
679+
680+
JpqlQueryParser.parseQuery("""
681+
select u
682+
from UserAccountEntity u
683+
join u.lossInspectorLimitConfiguration lil
684+
join u.companyTeam ct
685+
where exists (
686+
select iu
687+
from UserAccountEntity iu
688+
join iu.roles u2r
689+
join u2r.role r
690+
join r.rights r2r
691+
join r2r.right rt
692+
where
693+
rt.code = :rightCode
694+
and iu = u
695+
)
696+
and ct.id = :teamId
697+
""");
698+
}
699+
700+
@Test // GH-2864
701+
void usingLeftAsARelationshipNameShouldWork() {
702+
703+
JpqlQueryParser.parseQuery("""
704+
select u
705+
from UserAccountEntity u
706+
join u.lossInspectorLimitConfiguration lil
707+
join u.companyTeam ct
708+
where exists (
709+
select iu
710+
from UserAccountEntity iu
711+
join iu.roles u2r
712+
join u2r.role r
713+
join r.rights r2r
714+
join r2r.left lt
715+
where
716+
lt.code = :rightCode
717+
and iu = u
718+
)
719+
and ct.id = :teamId
720+
""");
721+
}
722+
723+
@Test // GH-2864
724+
void usingOuterAsARelationshipNameShouldWork() {
725+
726+
JpqlQueryParser.parseQuery("""
727+
select u
728+
from UserAccountEntity u
729+
join u.lossInspectorLimitConfiguration lil
730+
join u.companyTeam ct
731+
where exists (
732+
select iu
733+
from UserAccountEntity iu
734+
join iu.roles u2r
735+
join u2r.role r
736+
join r.rights r2r
737+
join r2r.outer ou
738+
where
739+
ou.code = :rightCode
740+
and iu = u
741+
)
742+
and ct.id = :teamId
743+
""");
744+
}
745+
746+
@Test // GH-2864
747+
void usingFullAsARelationshipNameShouldWork() {
748+
749+
JpqlQueryParser.parseQuery("""
750+
select u
751+
from UserAccountEntity u
752+
join u.lossInspectorLimitConfiguration lil
753+
join u.companyTeam ct
754+
where exists (
755+
select iu
756+
from UserAccountEntity iu
757+
join iu.roles u2r
758+
join u2r.role r
759+
join r.rights r2r
760+
join r2r.full fu
761+
where
762+
fu.code = :rightCode
763+
and iu = u
764+
)
765+
and ct.id = :teamId
766+
""");
767+
}
768+
769+
@Test // GH-2864
770+
void usingInnerAsARelationshipNameShouldWork() {
771+
772+
JpqlQueryParser.parseQuery("""
773+
select u
774+
from UserAccountEntity u
775+
join u.lossInspectorLimitConfiguration lil
776+
join u.companyTeam ct
777+
where exists (
778+
select iu
779+
from UserAccountEntity iu
780+
join iu.roles u2r
781+
join u2r.role r
782+
join r.rights r2r
783+
join r2r.inner inr
784+
where
785+
inr.code = :rightCode
786+
and iu = u
787+
)
788+
and ct.id = :teamId
789+
""");
790+
}
791+
677792
private void assertCountQuery(String originalQuery, String countQuery) {
678793
assertThat(createCountQueryFor(originalQuery)).isEqualTo(countQuery);
679794
}

0 commit comments

Comments
 (0)