On 2012-10-09 13:11, Bob MacCallum wrote:
> Hi all,
> I'm trying to get a Reporter query from the BASE2.x API which is
> basically "ORDER BY RAND(123)" - to get reproducible "random" order (I
> can explain *why* in another email if anyone cares to know).
> I tried this
> DataQuery<net.sf.basedb.core.data.ReporterData> repQuery =
> net.sf.basedb.core.Reporter.getQuery();
> repQuery.order(Orders.asc(new HqlExpression("RAND(123)", "xxx")));
> But it seems that HqlExpression isn't for public use.  I can't find
> something like "Expressions.hql".

This can be found in net.sf.basedb.core.query.Hql.expression(...)

> Could somebody please save me a ton of time and tell me how to put
> some arbitrary SQL into the ORDER BY clause of a DataQuery?

Note that it is not SQL that is needed but HQL (Hibernate Query 
Language). Don't know if RAND() is available in HQL. If not, it should 
be possible to create a custom Hibernate dialect and use that in the 
'db.dialect' setting in base.config. I have never done that so I don't 
know any details or how hard/easy it is.

Another possibility is to use Reporter.getDynamicQuery() instead which 
lets you work with SQL, but code-wise it's a bit harder to work with 
since you have to process the result row-by-row and column-by-column 
instead of as ReporterData objects.


Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
The BASE general discussion mailing list
unsubscribe: send a mail with subject "unsubscribe" to

Reply via email to