Laird Nelson
Laird Nelson

Reputation: 16196

How do I delimit a named parameter in JPQL?

I would like to write a JPQL query like this:

SELECT f
  FROM Foo f
 WHERE f.bar LIKE '[:bar]%'

This cannot be parsed properly by EclipseLink, which can't figure out that the trailing ]% is actually not part of the named parameter name.

I am aware of the ESCAPE keyword, but I'm not sure that would fix my problem. What are my spec-sanctioned options?

Upvotes: 1

Views: 64

Answers (1)

PepperBob
PepperBob

Reputation: 707

I'd say: create your query object with your query:

SELECT f FROM Foo f WHERE f.bar LIKE :bar

And then set the "bar" parameter by calling

query.setParameter("bar", "["+bar+"]%");

Upvotes: 1

Related Questions