1 Reply Latest reply on Jan 9, 2004 6:07 PM by sulfur

    JBossQL ORDER BY as Param?

    sulfur

      Hi all,

      I'm trying to feed in params for my ejbfinder using JBossQL. It works for WHERE, LIMIT, and OFFSET, but the param for ORDER BY is completely ignored (no exceptions thrown anywhere) & MySQL returns the unsorted collection.

      Is it valid to do so? Or would I have to use another approach, maybe a dynamic-ql?

      Thanks.

      My jbosscmp-jdbc.xml entry:


      <![CDATA[Test finder]]>
      <query-method>
      <method-name>findByFilter</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      <method-param>java.lang.String</method-param>
      <method-param>java.lang.String</method-param>
      <method-param>java.lang.String</method-param>
      <method-param>java.lang.Integer</method-param>
      <method-param>java.lang.Integer</method-param>
      </method-params>
      </query-method>

      <declared-sql>
      <![CDATA[SMPEntity]]>
      <![CDATA[unitHardwareId LIKE {0} AND partitionName LIKE {1} AND state LIKE {2}]]>
      <![CDATA[{3}]]> <![CDATA[LIMIT {4} OFFSET {5}]]>
      </declared-sql>


      If I explicitly put in a column name, eg <![CDATA[PartitionName DESC]]>, then it'll work as expected.

      My JBoss log:

      2004-01-09 12:13:54,203 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCDeclaredSQLQuery.SMPEntity#findByFilter] Executing SQL: SELECT SMPEntity.Id, SMPEntity.UnitHardwareId FROM SMPEntity SMPEntity WHERE unitHardwareId LIKE ? AND partitionName LIKE ? AND state LIKE ? ORDER BY ? LIMIT ? OFFSET ?

        • 1. Re: JBossQL ORDER BY as Param?
          sulfur

          BTW the problem is in the actual runtime call, since {3} is of String type, the param is fed into the SQL with single quotes around it,

          eg, ORDER BY 'State' (instead of the intended ORDER BY State)

          which is ignored by MySQL.

          fyi using MySQL 4.0.13 & JBoss 3.2.3.