-->
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: how to get a random fetch of records
PostPosted: Thu Jun 07, 2007 5:47 am 
Newbie

Joined: Thu Jun 07, 2007 5:44 am
Posts: 1
i need to get a series of random number to be compared to a table so as to fetch random questions from the table how can i acomplis this...

thanks in advance
Balaji.M


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 08, 2007 12:47 am 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
One way would be to have a column in the Question table whose value is a number..1,2,3,4...etc. This could be an id column for that matter.

Now you can generate a random number using Random, for example and do a select using "where id=<random>". You'd probably need to normalize the generated number.

_________________
Don't forget to rate the reply if it helps..:)

Budyanto


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 08, 2007 1:32 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

Query q=session.createQuery("from Animals ") ;

q.setFirstResult(random);
q.setFetchSize(1);

Amila

(Don't forget to rate if helps)


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.