4 Replies Latest reply on Nov 18, 2005 12:44 PM by Patrick Angeles

    Dynamic ORDER BY using hibernate/ejb3

    dornus Novice

      How do you create a dynamic 'order by' using HSQL?
      I don't want to inject it directly into the query because I would like to have it as a prepared statement. I am using MySql 5.0.13

      Ex.

       final Query q = em.createNativeQuery(
       "select * " +
       "from MyTable o " +
       "order by :columnName :columnDirection "+
       , MyTable.class
       );
       q.setParameter( "columnName", "myName" );
       q.setParameter( "columnDirection", "desc" );