EQL parsing fails with mismatched input #124

Closed
schueffi opened this Issue Dec 18, 2012 · 3 comments

Comments

Projects
None yet
3 participants
@schueffi

Parsing some of our named queries fail during deployment using batoo master as of today.

One of those queries is

13:45:26,997 ERROR [org.batoo.jpa.core.impl.criteria.jpql.JpqlQuery] (Query Manager [5]) Cannot parse query: 
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| SELECT a FROM DisplayConfiguration as a WHERE a.key = ?1                                                                                                                                                            |
|                                                                                                                                                                                                                     |
| [                                                                                                                                                                                                                   |
|     line 1:48 mismatched input 'key' expecting ID,                                                                                                                                                                  |
|                                                                                                                                                                                                                     |
| (SELECT (LSELECT (ST_ID_AS a))) (LFROM (ST_FROM (ST_ID_AS (LQUALIFIED DisplayConfiguration) a) LJOINS)) (WHERE (LOR (LAND (ST_PARENTED a <mismatched token: [@16,48:50='key',<77>,1:48], resync=key = ?1>)))) <EOF> |
| ]                                                                                                                                                                                                                   |
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The corresponding class is something like

@Entity
public class DisplayConfiguration extends Serializable {

long id;

String key;

@Id
get/setId();

get/setKey();
}

This error seems to occur if one of the properties is named with a "reserved" name according to jpa spec 4.4.1 - like "key" in the example above.

According to section 4.3, this restriction does not apply to state or relationship field names, as those names solely depend on the corresponding field name in the entity. So, this query is expected to work in accordance to the spec.

The restriction only applies for identification names (aka "as" alias names) and "named parameter" names.

Only for informational purpose: in both cases (when the restriction applies), a relaxing jpa implementation could parse the query nevertheless even if some "invalid" names are used, as the resulting evaluated BNF is clear without ambiguity in most cases. Hibernate does allow such cases for convenience, allthough it violates the spec.

@schueffi

This comment has been minimized.

Show comment Hide comment
@schueffi

schueffi Dec 18, 2012

Similar defective query is:

SELECT a.key FROM DisplayConfiguration as a

With error something like

|     line 1:8 mismatched input '.' expecting FROM                                                           

Similar defective query is:

SELECT a.key FROM DisplayConfiguration as a

With error something like

|     line 1:8 mismatched input '.' expecting FROM                                                           

@ghost ghost assigned hceylan Dec 18, 2012

@hceylan

This comment has been minimized.

Show comment Hide comment
@hceylan

hceylan Dec 18, 2012

Owner

@schueffi Thank you for once again digging the spec up for another specific case.

AFAIK, Hibernate too uses ANTLR for parsing, so if they can, we scould also work this around. We need to consult ANTLR documentation of handling of reserved words.

Owner

hceylan commented Dec 18, 2012

@schueffi Thank you for once again digging the spec up for another specific case.

AFAIK, Hibernate too uses ANTLR for parsing, so if they can, we scould also work this around. We need to consult ANTLR documentation of handling of reserved words.

@asimarslan

This comment has been minimized.

Show comment Hide comment
@asimarslan

asimarslan Mar 7, 2013

Owner

JPQL parser is fixed to handle this behavior.

Owner

asimarslan commented Mar 7, 2013

JPQL parser is fixed to handle this behavior.

@asimarslan asimarslan closed this Mar 7, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment