The best place to *find* answers to programming/development questions, imo, however it's the *worst* place to *ask* questions (if your first question/comment doesn't get any up-rating/response, then u can't ask anymore questions--ridiculously unrealistic), but again, a great reference for *finding* answers.

My Music (Nickleus)

20130116

[SOLVED] "unexpected AST node: :" - jpql named parameter can't contain period/full stop character, e.g. "transporter.name"

i had the following jpql in my java jee services bean:
select tad from TADS tad  WHERE tad.agreementOwnerId = :agreementOwnerId  AND upper(tad.transportCompany.name) LIKE :transporter.name ORDER BY tad.agreementNumber DESC, tad.id DESC

when i tried running the query i got the following error:

"unexpected AST node: :"

after some testing i found out that jpql query named parameters can't contain characters that are not a valid identifier as defined by Character.isJavaIdentifierPart e.g. period/full stop character (".").
e.g. a named parameter like "transporter.name" is invalid

the error message "unexpected AST node: :" was complaining about the ":" next to the named parameter "transporter.name", but the real problem was the "." in the named parameter. the named parameter should be rewritten to be something like "transporterName"

DOH!

so, this jqpl query string works:
select tad from TADS tad  WHERE tad.agreementOwnerId = :agreementOwnerId  AND upper(tad.transportCompany.name) LIKE :transporterName ORDER BY tad.agreementNumber DESC, tad.id DESC

afterwards, i found that this is also explained at stackoverflow:
JPA NamedQuery parameters

No comments:

Post a Comment