A colleague recently ran into a problem where he was passing in a single date parameter to a named query. In the query, the parameter was being used twice, once in an expression and once in a GROUP BY clause. Much to our surprise, we discovered that NHibernate used two variables and sent the single named parameter 开发者_如何学Pythonin twice, as @p1 and @p2. This behaviour caused SQL to fail the query, with the usual "a column in the select clause is not in the group by clause" (I paraphrase ofcourse).
Is this behaviour normal? Can it be changed? Seems to me that if you have a parameter name like :startDate, NHibernate only needs to pass in @p1 no matter how many times you might refer to :startDate in the query.
Any comments?
The problem was worked around by using another sub-query to overcome the SQL parsing error.
That can happen, for example, if the DB you are using does not support named parameters, in which case NHibernate uses positional ones, and it copies the value.
精彩评论