-->
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.  [ 3 posts ] 
Author Message
 Post subject: CreateQuery vs. find
PostPosted: Thu Apr 13, 2006 3:20 pm 
Newbie

Joined: Tue Aug 30, 2005 3:15 pm
Posts: 3
Hi, I am using Hibernate 2.1.7 and I noticed a weird behavior. I query a database using sess.createQuery(hql).setLong(0, parameter).list() and it is taking a long time, then I replaced it for sess.find(hql, new Object[] {parameter}, new Type[] {Hibernate.Long}) and it still took a long time. When I created I a hard coded string (hql) with the parameters and called sess.find(hql) the result was extremely fast, something like 100 times faster! Does anyone have an explanation for this?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 14, 2006 10:51 pm 
Regular
Regular

Joined: Wed Jul 07, 2004 2:00 pm
Posts: 64
You could set showSQL=true in your Hibernate.cfg.xml file, or the following in your log4j.properties file:
log4j.logger.org.hibernate.SQL=debug
log4j.logger.org.hibernate.type=debug

I prefer the later, since showSQL doesn't show the values for prepared statements.

This will show you the SQL that is being run and what values are being returned.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 15, 2006 8:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Once you have the SQL you can see the plan with an apporpiate tool.
I know early versions of Oracle (8i and earlier) executed queries with schewed data faster if it was hard coded rather than as a pararmeter, eg, archive character or either 'Y' / 'N' and there were many 'Y' and few 'N' as a paramemeter it would give equal weighting so a full scan would be performed but as a hard coded value it was able to view the stats and see 'N' was minimal so it used an index.


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