Re: Named query not working with parameters

From: Andrey Razumovsky (razumovsky.andre..mail.com)
Date: Wed Mar 03 2010 - 06:42:52 EST

  • Next message: Mike Kienenberger: "Re: cdbgen problem for SQLServer on RC2"

    With SQLTemplate, you must bind parameters using #bind directive. See
    http://cayenne.apache.org/doc/scripting-sqltemplate.html

    2010/3/3 Sudheer <sudheer.tec..mail.com>

    >
    > Query (computer_list) kept in datamap
    > ---------------
    > Select distinct cdh.dis_hw_uuid as id,
    > cdh.label as label,
    > 'computer' as col1,
    > ccd.class_name as col2,
    > cag.ip_address as col3,
    > cdh.vendor_name as col4,
    > cdh.class_id as state
    >
    > from xxx_discovered_hardware cdh left outer join xxx_class_def ccd on
    > ccd.class_id = cdh.class_id,
    > xxx_agent cag, xxx_n_tier dom
    >
    > where cdh.domain_uuid = dom.domain_uuid and cag.object_uuid =
    > cdh.dis_hw_uuid and cdh.label like $myParam
    >
    > Code for invocation
    > ------------------
    > SQLTemplate query = (SQLTemplate)
    > context.getEntityResolver().lookupQuery("computer_list");
    > HashMap input = new HashMap();
    > input.put("myParam", "ag15");
    > query.queryWithParameters(input);
    >
    > //NamedQuery query = new NamedQuery("computerlist", input);
    > List objects = context.performQuery(query);
    >
    > Log file after run
    > ----------------
    > INFO: --- transaction started.
    > 3/03/2010 15:59:49 org.apache.cayenne.access.QueryLogger logQuery
    > INFO: Select distinct cdh.dis_hw_uuid as id, cdh.label as
    > label, 'computer' as col1, ccd.class_name as col2,
    > cag.ip_address as col3, cdh.vendor_name as col4,
    > cdh.class_id as state from ca_discovered_hardware cdh left
    > outer join xxx_class_def ccd on ccd.class_id = cdh.class_id,
    > xxx_agent cag, xxx_n_tier dom where cdh.domain_uuid =
    > dom.domain_uuid
    > and cag.object_uuid = cdh.dis_hw_uuid and cdh.label like $myParam
    > 3/03/2010 15:59:49 org.apache.cayenne.access.QueryLogger logQueryError
    > INFO: *** error.
    > com.microsoft.sqlserver.jdbc.SQLServerException: Invalid pseudocolumn
    > "$myParam".
    > at
    >
    > com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(Unknown
    > Source)
    > at com.microsoft.sqlserver.jdbc.IOBuffer.processPackets(Unknown
    > Source)
    > at
    >
    > com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.getPrepExecResponse(Unknown
    > Source)
    > at
    >
    > com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(Unknown
    > Source)
    > at
    >
    > com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PreparedStatementExecutionRequest.executeStatement(Unknown
    > Source)
    > at com.microsoft.sqlserver.jdbc.CancelableRequest.execute(Unknown
    > Source)
    > at
    > com.microsoft.sqlserver.jdbc.SQLServerConnection.executeRequest(Unknown
    > Source)
    > at
    > com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(Unknown
    > Source)
    > at
    >
    > org.apache.cayenne.access.jdbc.SQLTemplateAction.execute(SQLTemplateAction.java:160)
    > at
    >
    > org.apache.cayenne.access.jdbc.SQLTemplateAction.performAction(SQLTemplateAction.java:134)
    > at
    >
    > org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:87)
    > at
    > org.apache.cayenne.access.DataNode.performQueries(DataNode.java:269)
    > at
    >
    > org.apache.cayenne.access.DataDomainQueryAction.runQuery(DataDomainQueryAction.java:422)
    > at
    >
    > org.apache.cayenne.access.DataDomainQueryAction.access$000(DataDomainQueryAction.java:69)
    > at
    >
    > org.apache.cayenne.access.DataDomainQueryAction$2.transform(DataDomainQueryAction.java:395)
    > at
    > org.apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:850)
    > at
    >
    > org.apache.cayenne.access.DataDomainQueryAction.runQueryInTransaction(DataDomainQueryAction.java:392)
    > at
    >
    > org.apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryAction.java:121)
    > at org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:743)
    > at
    >
    > org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:333)
    > at
    >
    > org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:96)
    > at
    > org.apache.cayenne.access.DataContext.onQuery(DataContext.java:1278)
    > at
    > org.apache.cayenne.access.DataContext.performQuery(DataContext.java:1267)
    > at Main.main(Main.java:85)
    >
    > Is there anything wrong I did?
    > --
    > View this message in context:
    > http://n3.nabble.com/Named-query-not-working-with-parameters-tp425935p425935.html
    > Sent from the Cayenne - User mailing list archive at Nabble.com.
    >

    -- 
    Andrey
    



    This archive was generated by hypermail 2.0.0 : Wed Mar 03 2010 - 06:43:51 EST