Parameterized Query in DataMap

From: Chandni Jain (chandni..ndrew.cmu.edu)
Date: Wed May 03 2006 - 12:52:08 EDT

  • Next message: Fredrik Liden: "Querying join table"

    Hello,

     

    I am trying to use Cayenee to connect to mysql database. I wanted to create
    a parameterized query and store it in DataMap so I can reuse the query.
    Please can you tell me how I should specify the query and how do I map the
    parameters.

    Currently this is what I am doing:

    In the datamap

    <query name="ParamDecompQuery"
    factory="org.objectstyle.cayenne.map.SQLTemplateBuilder" root="obj-entity"
    root-name="DesignModule">

                <sql
    adapter-class="org.objectstyle.cayenne.dba.mysql.MySQLAdapter"><![CDATA[SELE
    CT m.* FROM

      design_module m

      JOIN design_modulerefinementrelation d ON m.`factid`=d.child AND
    m.version=d.version

      JOIN __versions__ v ON m.version=v.id

    WHERE version_name=? AND d.parent=?]]></sql>

          </query>

     

    In the java code

     

    SQLTemplate DecomParamQuery = (SQLTemplate)
    context.getEntityResolver().lookupQuery("ParamDecompQuery");

                            Map params = new HashMap();

                            params.put("$version","Student_Example1");

                            params.put("$parent","<Fact-107>");

                            SQLTemplate newDecomParamQuery =
    DecomParamQuery.queryWithParameters(params);

     

    When I try to run the application I get an error that the parameter 1 is not
    set. If I use $ version instead on '?' in data map I get an error on invalid
    column name.

     

    Chandni

     



    This archive was generated by hypermail 2.0.0 : Wed May 03 2006 - 12:54:34 EDT