Hi Tony, Cayenne expressions don't support DB functions. You were on the correct path with the SQLTemplate which allows you to do more DB-specific things.
mrg On Tue, May 3, 2011 at 7:42 AM, Tony Dahbura <[email protected]> wrote: > I am trying to execute a where clause that includes calling a database > function, in this case SHA2 for mysql. > > My code looks like the following: > HashMap<String,String> parameters = new HashMap<String,String>(1); > parameters.put("userid", uid); > parameters.put("password", pwd); > > Expression expression = Expression.fromString("userid = $userid and > password=SHA2('$password',256)"); > SelectQuery query = new > SelectQuery(Adminuser.class,expression.expWithParameters(parameters)); > > List values = context.performQuery(query); > > Upon execution I immediately get an error that says: > Exception in thread "main" org.apache.cayenne.exp.ExpressionException: > [v.3.0.1 Aug 25 2010 19:42:04] Encountered " "(" "( "" at line 1, column 35. > Was expecting one of: > <EOF> > "or" ... > "and" ... > "+" ... > "-" ... > "*" ... > "/" ... > > at org.apache.cayenne.exp.Expression.fromString(Expression.java:139) > at trycayenne.validateAdminUserAndPassword(trycayenne.java:121) > at trycayenne.main(trycayenne.java:24) > Caused by: org.apache.cayenne.exp.parser.ParseException: Encountered " "(" "( > "" at line 1, column 35. > Was expecting one of: > <EOF> > "or" ... > "and" ... > "+" ... > "-" ... > "*" ... > "/" ... > > at > org.apache.cayenne.exp.parser.ExpressionParser.generateParseException(ExpressionParser.java:1487) > > Is Cayenne not able to pass database function calls in this kind of query? I > got it to work using the SQLTemplate rawSelect and typing the whole select > expression into the system, but was hoping I could use the Expression syntax. > > Should I pass the function name in a different manner? > > Thanks, > Tony > > > > > >
