Skip to content

Commit cdfe673

Browse files
committed
JPQL parser must support LEFT, INNER, and OUTER as possible identifiers.
1 parent 718cfa8 commit cdfe673

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
@@ -679,6 +679,121 @@ void queryParserPicksCorrectAliasAmidstMultipleAlises() {
679679
assertThat(alias("select u from User as u left join u.roles as r")).isEqualTo("u");
680680
}
681681

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

0 commit comments

Comments
 (0)