Reputation: 9697
I have a Query in hibernate which I believe is because of the VARCHAR and NVARCHAR discrepancies in the driver and MsSql discussed here Getting Hibernate and SQL Server to play nice with VARCHAR and NVARCHAR. I understand that this issue is not with Hibernate but am confused by the way hibernate deals with the code below .
When we ran the Queries below (using set parameter and without it), on a DB with VARCHAR column type for the column 'code' , we found that appending the string in HQL works lot faster that setParameter(or Criteria Query which should have been faster than HQL) .
Query createQuery = session.createQuery("from abc where code='"+substring+"'");
/*Query createQuery = session.createQuery("from abc where code=:substring");
createQuery.setParameter("substring","Test");*/
return createQuery.list();
Please let me know how this would make a difference.
Upvotes: 0
Views: 1538
Reputation: 692073
The execution plan computed by the database is probably different between the two queries. A similar problem is described in this question, and my DBA already told me that the same problem can appear with Oracle as well.
Upvotes: 0