Selecting random rows

#1

Hello is there way to get random rows? Functions like rand(), random(), newid() doesn't work ;/

for example:

em.createQuery("SELECT s FROM StawkaVat s ORDER BY rand()").setMaxResults(5).getResultList();

gives exception:

Exception in thread "AWT-EventQueue-0" [ObjectDB 2.5.6_02] SELECT s FROM StawkaVat s  ==> rand <== ()
javax.persistence.PersistenceException
Unexpected query token 'rand' (error 752)
(position 26) at com.objectdb.jpa.JpaQuery.getResultList(JpaQuery.java:725)
#2

You may use setFirstResult with a random number.

ObjectDB Support

Reply