1 Reply Latest reply on Apr 25, 2005 6:03 PM by Emmanuel Bernard

    How to do an order by in ejb 3.0

    bmhardy Newbie

      Thank for you for the wonderful preview package.

      I'm wondering how to sort a result set in ejb 3.0 with order by.

      I have an entity bean Automobile with a one to many relationship to another entity bean LeasePrice.
      I have succesfully created a finder method for entity Automobile. I can get the list of LeasePrices's from each Automobile.
      I would like to modify my finder method on Automobile so that the search result is ordered by a value found in LeasePrice.

      My ejbql looks like this:
      return manager.createQuery("from Automobile a where a.make = :make and a.model = :model")
      .setParameter("make", make)
      .setParameter("model", model)
      .setFirstResult(pos).setMaxResults(
      size).listResults();

      In sql I can get the output I want with a query like this:
      select * from automobile as a left join leasePrice as lp on a.id=lp.automobile_id_fk where lp.amount > 0 order by lp.amount;

      Is this trival? Can you point me in the right direction to order my ejbql using the value in the related entity bean?

      Thanks
      Brian