3 Replies Latest reply on Mar 8, 2007 12:51 PM by hanasakijiji

    Using a parameter as order by column

    milestone

      Hi all,

      I am developing a Rich Client talking to my jboss server via Session Beans. Now within my Session Bean, I have the following Function:

       public List<Domaindata> getAllDomains(String orderByColumn)
       {
       Query query = em.createQuery("select d from Domaindata AS d ORDER BY :column");
       query.setParameter("column", orderByColumn);
      
       return query.getResultList();
       }
      


      on the client side i am calling this function through its remote interface

       DomainRobotRemote robot = CommunicationHandler.getInstance().getDomainRobot();
       List<Domaindata> domains = robot.getAllDomains("name");
       for (Domaindata d : domains)
       {
       theNode.add(new DefaultMutableTreeNode(d.getName()));
       }
      


      I can see the query translated by hibernate as

      16:08:06,302 INFO [STDOUT] Hibernate: select ... borc.DOMAINDATA domaindata0_ order by ?
      


      but the result list is not ordered.

      If I explicitly order by a specific domain as in
       public List<Domaindata> getAllDomainsByName()
       {
       return em.createQuery("from Domaindata domain order by domain.name").getResultList();
       }
      


      Everything is working fine. Isn't it possible to dynamically say what Column I want the Result list to be orderd by?

      Any Help is highly appreciated.

      Juergen