Fórum

I need to get random rows using dynamic query

Ahmed Kamel, modificado 12 Anos atrás.

I need to get random rows using dynamic query

New Member Postagens: 13 Data de Entrada: 28/04/11 Postagens Recentes
I'm using dynamicQuery and i want to get random rows
thumbnail
Charles de Courval, modificado 12 Anos atrás.

RE: I need to get random rows using dynamic query

Junior Member Postagens: 55 Data de Entrada: 31/07/10 Postagens Recentes
What ??
You need to be more specific, to give more detail.
Ahmed Kamel, modificado 12 Anos atrás.

RE: I need to get random rows using dynamic query

New Member Postagens: 13 Data de Entrada: 28/04/11 Postagens Recentes
DynamicQuery dynamicQuery = new DynamicQueryFactoryUtil().forClass(Playlist.class);

List<Playlist> resultList = PlaylistLocalServiceUtil.dynamicQuery(dynamicQuery));


What I need to get random resultList? That is it!!!!!!!
thumbnail
Charles de Courval, modificado 12 Anos atrás.

RE: I need to get random rows using dynamic query

Junior Member Postagens: 55 Data de Entrada: 31/07/10 Postagens Recentes
Collection.shuffle( List ) could do the job.

Other wise you'd have to rely on you DB for random results and dynamicQuery won't help you there. You'd have to go with SQL and a FinderImpl class.
Thomas T., modificado 12 Anos atrás.

RE: I need to get random rows using dynamic query

New Member Postagens: 9 Data de Entrada: 11/02/11 Postagens Recentes
Collection.shuffle( List ) could do the job.


Not really. The list will always contain the same elements but in a different order. What Ahmed Kamel wants is random results. To get this you can use hibernate object
Restrictions.sqlRestriction("order by rand()")
in your query.