2 Replies Latest reply on Dec 5, 2002 1:15 PM by liu qiang

    problem using Dynamic-SQL in ORDER  BY

    liu qiang Newbie

      Hi! I am using the dynamic-QL plus Order By, I want to do the following:

      SELECT OBJECT(g) FROM UserInfo g ORDER BY ?1

      I pass the argument as:

      Object[] args= new Object[1];
      args[0]= "g." + OrderBY;
      //OrderBY is String--Column name I pass in

      But I got the following error message:

      [junit] There was 1 error:
      [junit] 1) testIVSSDataLayer_none(com.numeritech.ivss.dataLayer.ivstest)
      [junit] javax.ejb.FinderException: Error compiling ejbql: org.jboss.ejb.plugins.cmp.ejbql.ParseE
      tion: Encountered "1" at line 1, column 44.
      [junit] Was expecting one of:
      [junit] <NUMERIC_VALUED_PATH> ...
      [junit] <STRING_VALUED_PATH> ...
      [junit] <DATETIME_VALUED_PATH> ...
      [junit]
      [junit] at org.jboss.ejb.plugins.cmp.jdbc.JDBCDynamicQLQuery.execute(JDBCDynamicQLQuery.java

      [junit] at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCSelectorBridge.execute(JDBCSelectorBrid
      ava:64)
      [junit] at org.jboss.ejb.plugins.cmp.bridge.EntityBridgeInvocationHandler.invoke(EntityBridg
      ocationHandler.java:95)
      [junit] at org.jboss.proxy.compiler.Runtime.invoke(Runtime.java:59)
      _______________________________

      it seems Dynamic-QL doesnot support this, am I right? or I did something wrong.

      Thanks for reply !


        • 1. Re: problem using Dynamic-SQL in ORDER  BY
          Dain Sundstrom Master

          You can only order by a path statement, becaused it has to be converted into the actuall columns. Specifically, you can't order by a parameter. Since you are already using DynamicQL, I suggest you just generate a statement instead of passing a parameter. For example: [pre]
          String query = "SELECT OBJECT(g) FROM UserInfo g " +
          "ORDER BY g." + OrderBY;
          [/pre]

          • 2. Re: problem using Dynamic-SQL in ORDER  BY
            liu qiang Newbie

            Hi! I have trouble put this query as dynamic QL. can u give me a hint how to use the following query:

            String query = "select Object(g) FROM userInfo g" + "Order BY g." + OrderBy

            I read the CMP examples, it seems that when I use the Dynamic QL with Set ejbSelectGeneric(String jbossQl, Object[] arguments), the arguments are always required,
            while the above query doesnot have any argument, is there other ways to use Dynamic QL without using the ejbSelectGeneric ?


            Thanks!

            qiang