I've found a very strange problem in my code using Hibernate.
Parameterized query runs slower than a "plain" one.
For example I write:
Code:
String sQuery =
"SELECT {gn.*} FROM geo_name as {gn} " +
"WHERE {gn}.id >= 279641 AND {gn}.id < 279741 ";
Query query = session.createSQLQuery( sQuery, "gn", GeoName.class );
List result = query.list();
I takes only 132 ms. Good!
But If I use parameter in query
Code:
String sQuery =
"SELECT {gn.*} FROM geo_name as {gn} " +
"WHERE {gn}.id >= :id_fr AND {gn}.id < :id_to ";
Query query = session.createSQLQuery( sQuery, "gn", GeoName.class );
query.setInteger( "id_fr", 279641 );
query.setInteger( "id_to", 279741 );
return query.list();
The query takes 610 ms. Four times slower !!
This very strange and happens always. Have nobody experienced the same?
Any idea to solve it.
Thanks in advance for any idea or suggestion.
Paolo
Hibernate version: 2.1.6
Name and version of the database you are using: Sybase 12.5