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.  [ 1 post ] 
Author Message
 Post subject: :: Hibernate Pagination ::
PostPosted: Tue Nov 20, 2007 5:11 am 
Newbie

Joined: Mon Oct 29, 2007 4:08 am
Posts: 2
Hi

I have a Problem while doing pagination in Hibernate. we have more than 6000 operations, I had to implement Pagination in Hibernate Level.

The following is one of the method in settlementOperationDao class.

I have commented the lines required for Pagination
Here Order clause is mandatory
SetFirstResult and MaxResult are also mandatory.


/**
* @param lSpId
* @throws com.cavali.exception.BaseException
* @return
*/
public List findSettlementOperations(Long lSpId, int intPage ,
int intPageSize) throws BaseException { \* Here intPage and intPageSize
related to Pagenation */
Session session = null;
try {
session = HibernateUtil.currentSession();
Criteria objCr = session.createCriteria(SettlementOperations.class,
"so").createCriteria("so.settlementOperationHolderses",
"soh").add(
Expression
.eq("so.settlementProcesses.spIdProcessPk", lSpId))
.add(Expression.eq("so.soInWithdrawed", new Long(0))).add(
Expression.eq("soh.sohInWithdrawed", new Long(0)))
.addOrder(Order.asc("so.soIdSettlementPk")); // Pagination
objCr.setFirstResult(intPage * intPageSize); // Pagination
objCr.setMaxResults(intPageSize + 1); // Pagination
return objCr.list(); // Pagination
} catch (RuntimeException re) {
log.error("Exception occured in findSettlementOperations method",
re);
throw re;
} finally {
HibernateUtil.closeSession();
}
}


and In one of the method in BC Class I have called like the following.

/**
* registerParticipantPositions
*
* @param lngSPK
* Long
* @return String
* @throws BaseException
*/
private String registerParticipantPositions(Long lngSPK)
throws BaseException {

List lstSettlementOps = objSettlementOperationsDAO
.findSettlementOperations(lngSPK, 0, 500); // Call to Pagenation method
List lstSettlementOpsNew = new ArrayList();
int intPage = 0;
while(lstSettlementOps.size()>500){ // Checks whether nextPage exists or
not
lstSettlementOpsNew = lstSettlementOps.subList(0, 500-1); // Gets only
500 records
updateSettlementOpeAmount(lstSettlementOpsNew);
lstSettlementOps = null;
intPage++;
lstSettlementOps = objSettlementOperationsDAO
.findSettlementOperations(lngSPK, intPage, 500); // Call for nextPage
}
if(lstSettlementOps.size() != 0){
updateSettlementOpeAmount(lstSettlementOps);
}

int iStatus = calculateParticipantPosiCommon(lngSPK);
if (iStatus == 0) {
return "success";
} else {
return "fail";
}
}


I tested this code in my system. For 6000 operations it is working fine but I have 26000 operations for that I am getting exception.

I have already increased Transaction time and Memory Size for my OC4J application server.

Plz suggest me is there any better solution for pagination in hibernate.

Thanks in advance


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

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.