2 Replies Latest reply on Apr 9, 2007 9:42 AM by merabi

    random selection with ejbql

    merabi

      hi fellaz.

      I'm developing a web app using EJB3.0 and MySQL but I came up w/ the EJBQL problem.

      I need to write the EJBQL query to select RANDOM 150 records from a DB.

      Is there anyway I can do it?

      I know MySQL provides a rand() option and I know there is a method called createNativeQuery.

      but my boss doesn't wanna use createNativeQuery for some reason...

      Any info will be appreciated.
      THNX!

        • 1. Re: random selection with ejbql

           

          entityManager.createNativeQuery("SELECT * FROM <my_entity_table>", MyEntity.class).getResultList();
          


          Work for me!

          Regards

          Felix

          • 2. Re: random selection with ejbql
            merabi

            thanks for the reply, but I still need to know if EJBQL allows random selection from the record.

            for example, MySQL allows query:

            select * from Table1 order by rand() limit 5;

            I've searched half a day if EJBQL can do sucha thing but found no info.

            Is there anyway I can select random records using EJBQL?

            (My boss doesn't wanna use createNativeQuery. That make it more though...)