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.  [ 10 posts ] 
Author Message
 Post subject: Implementing Pagination
PostPosted: Tue Oct 31, 2006 12:20 am 
Newbie

Joined: Fri Oct 27, 2006 6:09 am
Posts: 5
Location: india
Hi all,

Iam new to Hibernate ,I need to implement pagination.My DAO class returning the list which contains all the records from here it is returning to the controller from there to JSP.
Please can any send me the code to implement pagination, i gone through the all the forums but iam not getting the idea how to fit that into my application.



Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 31, 2006 12:56 am 
Beginner
Beginner

Joined: Tue Aug 22, 2006 3:06 am
Posts: 25
see the reference


Top
 Profile  
 
 Post subject: iam unable find any solution at u r blog
PostPosted: Tue Oct 31, 2006 1:04 am 
Newbie

Joined: Fri Oct 27, 2006 6:09 am
Posts: 5
Location: india
iam unable to find any sol at your blog.could please send me the exact link



thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 31, 2006 1:16 am 
Beginner
Beginner

Joined: Tue Aug 22, 2006 3:06 am
Posts: 25
http://www.hibernate.org/hib_docs/v3/reference/en/html/objectstate.html#objectstate-querying-executing-pagination


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 31, 2006 1:16 am 
Beginner
Beginner

Joined: Fri Jun 02, 2006 1:23 am
Posts: 27
In the criteria object you can setMaxResults() and setFirstResult().

http://www.hibernate.org/hib_docs/v3/api/org/hibernate/Criteria.html


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 31, 2006 1:19 am 
Beginner
Beginner

Joined: Fri Jun 02, 2006 1:23 am
Posts: 27
doc reference,

http://www.hibernate.org/hib_docs/v3/reference/en/html/objectstate.html#objectstate-querying-executing-pagination

_________________
George F.
Don't forget to rate!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 31, 2006 1:31 am 
Newbie

Joined: Fri Oct 27, 2006 6:09 am
Posts: 5
Location: india
Thanks for your reply,


public List getTransactions(TransactionQueryDto transactionQuery){
List relatedOperations = null;
try {
String strQuery = ALL_TRANS_QUERY + getWhereClause(transactionQuery);
Session session = HibernateUtils.getInstance().currentSession();
Query objQuery = session.createQuery(strQuery);
/*
int totalRecords=relatedOperations.size();
objQuery.setFirstResult(0);
objQuery.setMaxResults(totalRecords);
*/
if(transactionQuery.isIncludeDate()){
if(transactionQuery.getFromDate()!=null){
objQuery.setDate("fromDate", transactionQuery.getFromDate());
}
if(transactionQuery.getToDate()!=null){
objQuery.setDate("toDate", transactionQuery.getToDate());
}
}
System.out.println("objQuery: "+objQuery);
relatedOperations = objQuery.list();


} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return relatedOperations;
}

this is my method whihc is returning all the records through the list..

please suggest me how to fit that code in to this



Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 31, 2006 3:01 am 
Regular
Regular

Joined: Mon May 08, 2006 6:00 am
Posts: 53
Location: India
can you have overloaded version of your given method as shown below, chech setting of fist and max results

public List getTransactions(TransactionQueryDto transactionQuery, int intFirstResult, int maxResults){
List relatedOperations = null;
try {
String strQuery = ALL_TRANS_QUERY + getWhereClause(transactionQuery);
Session session = HibernateUtils.getInstance().currentSession();
Query objQuery = session.createQuery(strQuery);
/*
int totalRecords=relatedOperations.size();
objQuery.setFirstResult(0);
objQuery.setMaxResults(totalRecords);
*/
if(transactionQuery.isIncludeDate()){
if(transactionQuery.getFromDate()!=null){
objQuery.setDate("fromDate", transactionQuery.getFromDate());
}
if(transactionQuery.getToDate()!=null){
objQuery.setDate("toDate", transactionQuery.getToDate());
}
}

objQuery.setMaxResults(intMaxResult)
objQuery.setFirstResult(intFirstResult).

System.out.println("objQuery: "+objQuery);
relatedOperations = objQuery.list();


} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return relatedOperations;
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 31, 2006 5:25 am 
Newbie

Joined: Fri Oct 27, 2006 6:09 am
Posts: 5
Location: india
Thanks for u r reply i will try that method ....


Top
 Profile  
 
 Post subject: iam unable execute that overloaded method which u suggested
PostPosted: Thu Nov 02, 2006 1:46 am 
Newbie

Joined: Fri Oct 27, 2006 6:09 am
Posts: 5
Location: india
[quote="hyper"]Thanks for u r reply i will try that method ....[/quote]

I tried that overloaded method but how can i pass that maxResults from a JSP with out executing a query .(ie; we don't know the maxResults value while passing from the JSP we can only pass the firstResults Value)


Please reply ASAP


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