-->
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.  [ 4 posts ] 
Author Message
 Post subject: setParamter () much slower than setString (), setLong ()....
PostPosted: Mon Jun 23, 2008 8:28 am 
Newbie

Joined: Sun Dec 30, 2007 1:08 pm
Posts: 14
Hi,
I've noticed that using setParameter of the Query object is much slower than using the "typed" methods like setString(), setLong() etc.
I would expect that from the setParameter() version without the Type parameter because Hibernate needs to find out what Type is actually needed, but even the setParameter() call with the correct Type is slower than the typed method version.

I am using Hibernate 3.2.2. Maybe it is already fixed in the current version?

Is this a know behaviour of this method? If so (and if I'm not wrong ;-)) it would be nice if you could stress the fact in the javadocs of this method.
If you try to implement a generic DAO base class you tend to use the setParameter() method and not the typed ones. This will cause a performance reduction at the basis of all DAO implementations!

My development environment:
Java 1.4.2
Hibernate 3.2.2.
DB: Oracle 10g
Oracle Driver Implementation Version: 10.2.0.3.0

Best regards,

Christian


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 23, 2008 5:51 pm 
Newbie

Joined: Sun Dec 30, 2007 1:08 pm
Posts: 14
Tried it at home with an Oracle Express and a different database. There was no difference in the query execution time. I guess it is an issue with the oracle version/database/driver/ combination at work.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 24, 2008 10:13 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
I too had never seen a significant difference in the two method calls, which made your original post somewhat curious. Time to figure out what the heck is going on with those JDBC drivers at work!

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Re: setParamter () much slower than setString (), setLong ()....
PostPosted: Sat Jun 27, 2009 8:22 am 
Newbie

Joined: Sun Dec 30, 2007 1:08 pm
Posts: 14
I've found the explanation for this behaviour. It is simple and clear but it can be overlooked easily...
I simply made a mistake in my mapping file. A property of my Hibernate Pojo was mapped as an int but the column
type in the oracle database was a vachar2! I know that there are only integers in the database, therefore I've never noticed the wrong column type...
Oracle (and maybe other databases too?) is extremely bad when it comes to type conversion. Even when you execute a SQL statement directly (e.g. in Toad) you get a noticeable performance drop if you provide a numerical parameter for a varchar2 column.
Is there a way to produce an error message for this? I've written some test code that compares the Hibernate Metadata with the Metadata that is returned from a JDBC ResultSet to find other mapping mistakes in my Hibernate mapping files. This works for me, but a more general solution might be helpful.

Chris


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