-->
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: How to Improve performance of query?
PostPosted: Thu Oct 29, 2009 3:43 am 
Newbie

Joined: Wed Oct 07, 2009 8:37 am
Posts: 2
Hi I have written a function which fetch one city of a particular state the hbm mapping of files are given below:

city.hbm

<id name="id" type="integer">
<generator class="sequence">
<param name="sequence">city_sequence</param>
</generator>
</id>

<property name="name">
<column name="name"/>
</property>

<many-to-one name="State" class="com.abc.State">
<column name="site" sql-type="number"/>
</many-to-one>

State.hbm

<id name="id" type="integer">
<generator class="sequence">
<param name="sequence">state_sequence</param>
</generator>
</id>

<set name="city" inverse="true" cascade="all-delete-orphan">
<key column="site"/>
<one-to-many class="com.abc.City"/>
</set>

From my action class I am calling the method

City city = cityService.getCity(String cityName, State state);

IMPL class Method:

public City getCity(String cityName,State state) {

City city = null;
Session session = getSession();
try {
Criteria criteria = session.createCriteria(City.class);
criteria.add(Restrictions.eq("name", cityName))
.add(Restrictions.eq("state.id", state.getId()))

city = (City) criteria.uniqueResult();
if (city == null) {

throw new ObjectRetrievalFailureException(City.class, cityName);
}
}
catch( Exception e ) {
if (log.isDebugEnabled())
log.debug("[getCity and State] "+e);
log.error("[getCity and State ] "+e.getMessage());
}
return city;
}



The whole application invokes when I upload some users into database, before uploading users I also checked the city related to that user for that I invoke above method. The method works fine with few records but it takes lot of time when we upload say 5000 users.
I also put debug statements and found that to execute the
city = (City) criteria.uniqueResult();
it takes 4ms for first record then it keeps on increasing and reached to 150 ms for 8000 users.

I had also tried to put second level caching, as a result the SQL query is not executing every time but it still takes same time .

Please provide some solution. Thanks


Top
 Profile  
 
 Post subject: Re: How to Improve performance of query?
PostPosted: Thu Oct 29, 2009 3:27 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
You're most likely getting hit with auto flushes. As more objects are kicking around in your session the flush checks are going to take longer and longer. Do a search for batch processing as sounds like the code you're working with is some sort of import?

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


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.