-->
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.  [ 4 posts ] 
Author Message
 Post subject: Random Select Query on Hibernate 2.1.6
PostPosted: Tue Nov 16, 2004 1:53 pm 
Newbie

Joined: Tue Nov 16, 2004 1:46 pm
Posts: 2
Location: Manila, Philippines
Is there a way to do a random select query on Hibernate 2.1.6?

Usually I do this random select query on MySQL by using this SQL:

select * from answer order by rand() limit 1;

I'm looking for a way on how to do this in Hibernate. Can I use the rand() function in HQL? Or is there a specific util class that I can use in Hibernate?

I'm also looking for a way to limit the query result. Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 16, 2004 1:55 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The order by clause in HQL is passed through to the database, so you can use any function. This and your other question is answered in the HQL chapter of the reference documentation.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 16, 2004 2:33 pm 
Newbie

Joined: Tue Nov 16, 2004 1:46 pm
Posts: 2
Location: Manila, Philippines
Thanks for the reply Christian!

Is there also a way of doing this random query and select query limit using Hibernate without applying specific functions from the db in the HQL (for example rand() and limit in MySQL). I'm thinking of something like an API class or method that I can use in Hibernate (if there's any). As much as possible I'm refraining from using db specific functions in the HQL.

christian wrote:
The order by clause in HQL is passed through to the database, so you can use any function. This and your other question is answered in the HQL chapter of the reference documentation.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 16, 2004 2:35 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
No, but you can certainly write your own extensions somehow.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.