Wrong number of parameters sent on Criteria query when a custom projection contains parameters itself

Description

When one implements IProjection such that this projection contains parameters, NH 3.3.0 fail to send these parameters in the query (NH 3.1.0 does not).
If one applies Projections.GroupProperty(customProjection), the parameters in the projection are sent only once (for the SELECT clause), while the parameters in the GROUP BY clause are positional and missing in the query (in both 3.1.0 and 3.3.0).
I have attached a small console project that reproduces the bug. The only things that need to be changed to run are the connection string and the driver/dialect settings in hibernate.cfg.xml, and comment/uncomment the proxyfactory line depending on the NHibernate version you are trying it with, besided referencing the correct dlls, of course.

You will also need to create a small test table in your db called "test_table" like this:
"test_table":
--------------------------------------
id (int) | number (int)

You can put whatever values you want to run the attached project.

I'm using .NET 4 in Mono with Npgsql, although I think this is not relevant to this problem. The project attached references NHibernate 3.1.0GA. I didn't mention NHibernate 3.2.0GA not because it works, but because I haven't tried to run with it.

Environment

None

Attachments

1
  • 26 Apr 2012, 12:15 AM

Activity

Show:

Marcelo Zabani July 1, 2012 at 9:35 PM

I find it strange that this may be intented behavior, because there is no impediment to us as programmers to pass an IProjection that includes parameters to ICriteria.SetProjection(params IProjection[] projections) or Projections.GroupProperty(IProjection projection), or many other methods that take an IProjection. Since IProjections may or may not include parameters, shouldn't it be that any methods receiving an IProjection should either be documented to not work with IProjections that include parameters (and, say, throw an exception in such a case), or should all take into account the possibility that ICriterias may include them, and work as expected in these cases too? (I may be pushing the bar here when I expect all methods that take IProjection to act differently according to the passed IProjection's including or not parameters, but I think what I am asking works more as naive users such as myself expect).

Thank you for your attention.

Oskar Berggren June 11, 2012 at 6:37 PM

Regression occurred before 3.2.0GA was released.

Oskar Berggren June 6, 2012 at 1:02 PM

Regarding the first part, which worked in 3.1, the regression occurred with ad215dacfb42ea848568d37d578c8356f075d808 from 2011-06-05. Unfortunately the commit is huge. It's noteworthy though that it contains a change in how the built in projection AddNumberProjection handles parameters. I suppose it might be that this is a intended breaking change rather than a regression, but I'm not sure.

Marcelo Zabani May 31, 2012 at 2:18 AM

It is because there are actually 2 very similar bugs described (maybe I should've created two issue reports).
One of the issues - generated query does not contain all parameters when a custom IProjection that includes parameters is used - seems to affect only NH 3.3.
The other issue exists in both NH 3.1 and NH 3.3: Using the same IProjection described in the line above in a Projections.GroupProperty() includes question marks "?" in the query. The corresponding positional parameters, however, are not sent with the query.
The small project that reproduces the bugs has some comments to help make the issues clear.

If there is anything else I can help with, please let me know.

Oskar Berggren May 30, 2012 at 6:24 PM

You state:
"NH 3.3.0 fail to send these parameters in the query (NH 3.1.0 does not)."

which to me sounds like you are saying that it works in 3.1. But you have stated 3.1 as an affected version. Please clarify.

Duplicate

Details

Assignee

Reporter

Labels

Components

Affects versions

Priority

Who's Looking?

Open Who's Looking?

Created April 26, 2012 at 12:15 AM
Updated September 4, 2015 at 2:25 PM
Resolved September 4, 2015 at 2:25 PM
Who's Looking?