Try this instead: final Expression queryTemplate = Expression.fromString("persname.familyName like '$name'"); Map<String,String> queryParams = Maps.newHashMapWithExpectedSize(1); queryParams.put("name", "A%"); // TODO "A" from parameter
I believe the wildcard (%) has to go into the map and not the expression. mrg On Tue, Sep 8, 2009 at 11:19 AM, Reinout van Schouwen<rein...@gmail.com> wrote: > Hi, > > I have a table Person and a table PersName. I've created a relation > between PersName and Person so that each PersName links to a Person. In > other words, a Person may have multiple PersNames. > > Is it possible to do a query like this: > > // find all Persons whose family name starts with A > final Expression queryTemplate = Expression.fromString("persname.familyName > like '$name%'"); > Map<String,String> queryParams = Maps.newHashMapWithExpectedSize(1); > queryParams.put("name", "A"); // TODO "A" from parameter > Expression qualifier = queryTemplate.expWithParameters(queryParams); > SelectQuery query = new SelectQuery(Person.class, qualifier); > query.addOrdering("familyName", true); > > When I try this, I get: > org.apache.cayenne.exp.ExpressionException: [v.2.0.4 October 12 2007] Can't > resolve path component: [Person.persname]. > > It is true that the table Person has no field 'persname' but if I read > http://cayenne.apache.org/doc20/building-expressions.html correctly, > Cayenne should automatically determine all the join information. > > How should I build the key path expression? > > regards, > > -- > Reinout van Schouwen > >