5 Replies Latest reply on Feb 1, 2007 12:49 PM by fhh

    @NamedQuery and setting orderBy as a parameter?

    freak hagga Newbie

      Lets say you have a ton of records in a content table, and a lot of criteria to determine appropriate content.

      How would you specify the orderBy and sort on a @NamedQuery, say as a parameter or by overriding the default orderby etc. ?

      I know i can annotate a bunch of @NamedQuery's but do I have to go and do the same huge query for every different orderBY and sort ? This will end up with at least 8-columns x 2 (asc|desc) = 16 named-queries, then if we alter the criteria, add another 16 named-queries. Its cr8zy.

      It just seems to be begging for this simplicity:

      Query q = em.createNamedQuery("findHottestContent");
      q.setParameter("orderBy", "viewsWeekly desc");

      Too many records to just load into a collection and post-sort like most documentation suggest doing, thats why there is an "order by" clause in SQL, thats what databases are good at.

      I know I can do a native query but then I end up with cache issues.

      Any ideas or coming patches to solve this?