Properly handle reserved words as entity names.
In JPQL and HQL, we need to properly handle reserved words that crop up as entity names (which is legal). See #2982.
This commit is contained in:
@@ -713,6 +713,7 @@ reservedWord
|
||||
| FETCH
|
||||
| FILTER
|
||||
| FIRST
|
||||
| FLOOR
|
||||
| FOLLOWING
|
||||
| FOR
|
||||
| FORMAT
|
||||
|
||||
@@ -596,12 +596,13 @@ trim_character
|
||||
|
||||
identification_variable
|
||||
: IDENTIFICATION_VARIABLE
|
||||
| ORDER // Gap in the spec requires supporting 'Order' as an entity name
|
||||
| COUNT // Gap in the spec requires supporting 'count' as a possible name
|
||||
| KEY // Gap in the sepc requires supported 'key' as a possible name
|
||||
| LEFT
|
||||
| f=(COUNT
|
||||
| INNER
|
||||
| KEY
|
||||
| LEFT
|
||||
| ORDER
|
||||
| OUTER
|
||||
| FLOOR)
|
||||
;
|
||||
|
||||
constructor_name
|
||||
@@ -682,8 +683,7 @@ collection_value_field
|
||||
;
|
||||
|
||||
entity_name
|
||||
: identification_variable
|
||||
| identification_variable ('.' identification_variable)* // Hibernate sometimes expands the entity name to FQDN when using named queries
|
||||
: identification_variable ('.' identification_variable)* // Hibernate sometimes expands the entity name to FQDN when using named queries
|
||||
;
|
||||
|
||||
result_variable
|
||||
|
||||
@@ -2118,12 +2118,8 @@ class JpqlQueryRenderer extends JpqlBaseVisitor<List<JpaQueryParsingToken>> {
|
||||
|
||||
if (ctx.IDENTIFICATION_VARIABLE() != null) {
|
||||
return List.of(new JpaQueryParsingToken(ctx.IDENTIFICATION_VARIABLE()));
|
||||
} else if (ctx.COUNT() != null) {
|
||||
return List.of(new JpaQueryParsingToken(ctx.COUNT()));
|
||||
} else if (ctx.ORDER() != null) {
|
||||
return List.of(new JpaQueryParsingToken(ctx.ORDER()));
|
||||
} else if (ctx.KEY() != null) {
|
||||
return List.of(new JpaQueryParsingToken(ctx.KEY()));
|
||||
} else if (ctx.f != null) {
|
||||
return List.of(new JpaQueryParsingToken(ctx.f));
|
||||
} else {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@@ -1499,4 +1499,21 @@ class HqlQueryRendererTests {
|
||||
select sr from maxId m join SnapshotReference sr on sr.snapshot.id = m.snapshotId
|
||||
""");
|
||||
}
|
||||
|
||||
@Test // GH-2982
|
||||
void floorShouldBeValidEntityName() {
|
||||
|
||||
assertQuery("""
|
||||
SELECT f
|
||||
FROM Floor f
|
||||
WHERE f.name = :name
|
||||
""");
|
||||
|
||||
assertQuery("""
|
||||
SELECT r
|
||||
FROM Room r
|
||||
JOIN r.floor f
|
||||
WHERE f.name = :name
|
||||
""");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -914,4 +914,21 @@ class JpqlQueryRendererTests {
|
||||
WHERE l.product.name = ?1
|
||||
""");
|
||||
}
|
||||
|
||||
@Test // GH-2982
|
||||
void floorShouldBeValidEntityName() {
|
||||
|
||||
assertQuery("""
|
||||
SELECT f
|
||||
FROM Floor f
|
||||
WHERE f.name = :name
|
||||
""");
|
||||
|
||||
assertQuery("""
|
||||
SELECT r
|
||||
FROM Room r
|
||||
JOIN r.floor f
|
||||
WHERE f.name = :name
|
||||
""");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user