java - Parameter as Left Hand Side Operator LIKE JPQL -
i’m trying execute following query: (using eclipselink 2.5.2, mysql 5.5)
em.createquery("select r region r (:pattern concat(r.pattern, '%'))") .setparameter("pattern", "eu.fr.pr") .getresultlist();
(background: i’m trying find super regions of region. super regions of eu.fr.pr
eu.fr
, eu
.)
however throws following exception:
java.lang.illegalargumentexception: have attempted set value of type class java.lang.string parameter pattern expected type of class java.lang.boolean query string
the oracle docs state
a expression determines whether wildcard pattern matches string.
the relevant parts of region
class are:
@entity @namedquery(name="region.findall", query="select r region r") public class region implements serializable { private static final long serialversionuid = 1l; @id @generatedvalue(strategy=generationtype.identity) private int id; private string pattern; public region() { } public string getpattern() { return this.pattern; } public void setpattern(string pattern) { this.pattern = pattern; } }
here sample data table:
+----+-------------+ | id | pattern | +----+-------------+ | 3 | eu | | 5 | eu.fr | | 6 | eu.fr.al | | 13 | eu.fr.lu | | 14 | eu.fr.pr | | 15 | eu.fr.pr.ba | | 16 | eu.fr.pr.ca | | 17 | eu.fr.pr.pa | | 18 | eu.fr.rh | | 19 | eu.fr.rh.tv | | 20 | eu.fr.ro | +----+-------------+
so why should pass boolean?
directly concatenating region query ("select r region r ('" + theregion + "' concat(r.pattern, '%'))"
) gives expected results not want in production. bug in eclipselink?
Comments
Post a Comment