cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chandni Jain" <chand...@andrew.cmu.edu>
Subject Parameterized Query in DataMap
Date Wed, 03 May 2006 16:52:08 GMT
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 

 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message