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.  [ 2 posts ] 
Author Message
 Post subject: Newbie : Hibernate optimization trics
PostPosted: Mon Jun 05, 2006 9:52 am 
Newbie

Joined: Mon Jun 05, 2006 9:48 am
Posts: 3
Hi,

I'm developing a web application using spring and hibernate and Mysql. My database contains huge records (more than 2 lacs). Most of the time, for each user, i need to fire a query to select a considerable number of records (say 20 thousand). After fetching the result i need to disply it using pagination. So i don't nedd all the records at the same time, but by clicking on the next page (or a specific page number) link i need to show the respective records.

While executing the query, it takes long time and responds with out of memory error. I tried setting getHibernateTemplate().setFetchSize(200) but the performance is same. I tried different combination of changing the mysql driver, setting hibernate.jdbc.batch_size but all in vain.

How i can resolve this performance issue? wat approach i can follow to solve this? What parameters i need to take care for a large database application like this?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 05, 2006 12:20 pm 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
You need:

in hibernate.cfg.xml
Code:
<property name="hibernate.connection.url">jdbc:mysql://hostname/schemaname?useServerPrepStmts=false</property>


doing the query, something like this
(final MAX_PAGE_RESULT = 200 or configurable or whatever you need,
nPage = the page you want to view begining with 0,)

Code:
session.createQuery(hql)
.setMaxResults(MAX_PAGE_RESULT)
.setFirstResult(nPage * MAX_PAGE_RESULT)
.list();
or
Code:
session.createQuery(hql)
.setMaxResults(MAX_PAGE_RESULT)
.setFirstResult(nPage * MAX_PAGE_RESULT + 1)
.list();
I don't remember.


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