-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: HQL Query with rand() and limit
PostPosted: Fri Feb 16, 2007 10:52 pm 
Newbie

Joined: Fri Feb 16, 2007 10:30 pm
Posts: 2
I'm currently using 3.1, and having some issues with pulling a random single record from my database.

The mysql query utilizes the following format: "select * from table order by rand() limit 1"

This query results in one random record from the DB. With HQL, it throws an error on "limit" in the form of: unexpected token.

I've searched and found a few similar errors, but no result. Currently, I'm grabbing the entire set utilizing order by rand(), and just using the first or last row returned. The problem with this is that the DB size grows, the List size will as well.

Thoughts?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 17, 2007 7:00 am 
Regular
Regular

Joined: Sun Sep 17, 2006 2:48 am
Posts: 81
Location: California
For limit you can use setMaxResults(1) on query object.

Hope that helps.
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 22, 2007 11:18 pm 
Newbie

Joined: Fri Feb 16, 2007 10:30 pm
Posts: 2
somu wrote:
For limit you can use setMaxResults(1) on query object.

Hope that helps.
Thanks


Thanks, it appears this is exactly what I needed. Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.