-->
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: speed issue
PostPosted: Mon Jan 05, 2009 12:26 am 
Newbie

Joined: Tue Feb 20, 2007 10:00 pm
Posts: 8
Hi,

I am having an issue with a query taking much longer than I think it should.

I am using Hibernate via the Java persistence API. When performing my query using EntityManager.createQuery.getResultList, it takes 35 seconds to retrieve about 400 records. I put together a raw SQL query get the same data. When using raw sql, fetching the corresponding records and creating the Java objects takes around .5 seconds.

I am fetching data for two classes. B is a subclass of A, D is a subclass of C and there is a one to many relationship between base class A and subclass D. With Hibernate, I am trying to fetch instances of class B. The query should create 70 instances of class B, each of which has a set of 5 D's. All my fetches are specified as eager.

When I turn on show_sql, I am seeing 157 queries being generated for each call to getResultList, but only 7 of the queries are unique. Class D references a couple of other classes, so 7 queries seems about right.

I ran the fetch twice using Hibernate to see if there is some kind of initialization overhead which would not be incurred on fetches after the first, but I am getting the same times and number of generated queries both times. I have another fetch which seems like it should be much more complex (13 classes/tables) which only takes 1 second to return about the same number of objects using Hibernate.

I suspect the speed issue is related to the high number of queries being generated. Any suggestions on what is going on and if there is a way to speed up the query ?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 05, 2009 4:23 am 
Regular
Regular

Joined: Wed Oct 15, 2008 6:59 am
Posts: 103
Location: Chennai
i think u will use criteria api with association or use select clause for specific fields or turn off lazy loading.

_________________
If u feel it will help you, don't forget to rate me....


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.