I have the following HQL query
Query q = session.createQuery
("Select j.salaryStartRange From Job j where region like (:region) and
uniquejobid in (:ujIds) and j.salaryStartRange > 10000
and (:degreeName) in elements(j.areasOfStudy) order by rand()");
q.setParameterList("ujIds", ujIds);
q.setParameter("region", region);
q.setParameter("degreeName", degreeName);
It seems that the query time is the same no matter whether I use:
List<Integer> result = q.setFirstResult(0).setMaxResults(100).list();
or
List<Integer> result = q.list();
IN other words the full query of possible results is conducted in both queries. THe maxResults limit seems to be set only once the query is complete. I only want to query for a random selection of 100 records (out of potentially thousands of records). How do I create such a query?
In sum: How do I randomly query 100 out of 10000 records as efficiently as possible?