Re: binding Collections to SQLTemplate

From: Bryan Lewis (brya..aine.rr.com)
Date: Sun Oct 22 2006 - 11:05:23 EDT

  • Next message: Michael Gentry: "Re: Re: Cayenne not taking account of PKs created by external SQL script"

    Never mind. I found the solution with more perusal of the docs and
    mailing list.

    select t.* from tablename t where t.state IN (#bind($states 'CHAR'))

    Bryan Lewis wrote:
    > I'm trying to use a SQLTemplate with an 'IN' expression and binding a
    > Collection, as described in the docs for "Scripting SQLTemplate". I
    > keep getting an error like this:
    >
    > org.apache.velocity.exception.ParseErrorException: Can't determine JDBC
    > type of binding ([AR, HI], null) at line 1, column 93
    > at
    > org.objectstyle.cayenne.access.jdbc.BindDirective.render(BindDirective.java:134)
    > at
    > org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:153)
    > at
    > org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:271)
    > at
    > org.objectstyle.cayenne.access.jdbc.SQLTemplateProcessor.buildStatement(SQLTemplateProcessor.java:232)
    > at
    > org.objectstyle.cayenne.access.jdbc.SQLTemplateProcessor.processTemplate(SQLTemplateProcessor.java:192)
    > at
    > org.objectstyle.cayenne.access.jdbc.SQLTemplateAction.performAction(SQLTemplateAction.java:136)
    >
    > The code:
    >
    > String sql = "select t.* from tablename t where t.state IN (#bind($states))";
    > Map parms = new HashMap();
    > parms.put("states", Arrays.asList(new String[] { "AR", "HI"}));
    > SQLTemplate query = new SQLTemplate(MyObject.class, sql);
    > query.setFetchLimit(maxListSize);
    > query.setParameters(parms);
    > List objects = dataContext.performQuery(query);
    >
    >
    >
    > Other bindings, not involving Collections, are working fine.
    >
    > I took a glance at the source and it appears that the wrong method is
    > being called. The render() method BindDirective.java:134 doesn't check
    > for the value being a Collection, but the other render() method does.
    > Maybe I need to specify something else?
    >
    >
    >
    >



    This archive was generated by hypermail 2.0.0 : Mon Oct 23 2006 - 13:38:55 EDT