NHibernate Named Query Parameter Numbering @ p1 @ p2 etc.

Recently, a colleague ran into a problem when he passed a named request in a single date parameter. In the query, the parameter was used twice, once in the expression and once in the GROUP BY clause. To our great surprise, we found that NHibernate used two variables and sent the same parameter twice, like @ p1 and @ p2. This behavior caused the SQL query to refuse the query because the usual “column in the select clause is not included in the group by clause” (I rephrase).

Is this normal behavior? Can this be changed? It seems to me that if you have a parameter name, for example: startDate, NHibernate needs to be passed only to @ p1 no matter how many times you could refer: startDate in the request.

Any comments?

The problem was resolved using another subquery to overcome the SQL parsing error.

+3
source share
1 answer

This can happen, for example, if the database you are using does not support named parameters, in which case NHibernate uses positional, and it copies the value.

0
source

Source: https://habr.com/ru/post/1750581/


All Articles