Hibernate version:
2.0.1.4000
.NET version
2.0
Database
MS SQL 2005
Hello everyone.
Today I found that at the first sight harmless query might bring a lot of problems. Consider this code, which loads an object id by url using stored procedure:
Code:
string urlNameWithoutWww = urlName;
string urlNameWithWww = CONST_WWWPrefix + urlName;
IQuery query = session.CreateSQLQuery(@"EXEC [dbo].[GetObjectId] @hostname = :name, @hostname2 = :name2");
query.SetString("name", urlNameWithoutWww);
query.SetString("name2", urlNameWithWww);
int id = query.UniqueResult<int>();
Rarely returned result wasn’t an int and the UniqueResult failed. I had changed the last line to the following:
Code:
IList list = query.List();
So, I could parse result by myself and see what is actually here. To my surprise sometimes the resulting list contained not a single value, but a list of values from more than 20 items. And what is more interesting if there was a single int in the resultset (as expected) it’s value could be invalid from the point that it doesn’t corresponds to provided hostnames.
I have a strong feeling that somewhere under the hood NHibernate mess with resultsets and some queries receive results of other queries. I am not sure if it is actually NHibernate problem, or the problem of .NET itself. I strongly believe that the problem is related to the
http://forum.hibernate.org/viewtopic.ph ... getordinal post. This happens only if a lot of requests come to web server at the same time.
I am interesting if anyone had faced such a problem? It is of
urgent importance to me since it looks like I can’t trust NHibernate anymore. Every single query result must be checked to make sure it belongs to that query.