Selecting random rows


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 <== ()
Unexpected query token 'rand' (error 752)
(position 26) at com.objectdb.jpa.JpaQuery.getResultList(

You may use setFirstResult with a random number.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login