NHibernate SQL Parameter on IBM.Data.DB2.iSeries provider

Description

I would like to report a bug on NHibernate v3.2.0.GA using IBM.Data.DB2.iSeries.dll (v7.1) reproduction of the error are as follows:

Assuming we have a table USERS consisting of fields USER_ID, FULL_NAME, PASSWORD. NHibernate can easily retrieve all the records by issuing the statement:

Session.CreateCriteria(Of objUsers).List(Of objUsers)();

However, when trying to add a criteria :

Session.CreateCriteria(Of objUsers).Add(Restrictions.InsensitiveLike("FULL_NAME", "john", MatchMode.Anywhere)).List(Of objUsers)();

NHibernate generates an error:

"Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"

Browsing the source code of NHibernate led me to the routine that is causing the error:

File Name: DriverBase.cs
Function: RemoveUnusedCommandParameters()
Code: cmd.Parameters
.Cast<IDbDataParameter>()
.Select(p => p.ParameterName)
.Except(formatter.AssignedParameterNames)
.ToList()
.ForEach(ununsedParameterName =>
{
cmd.Parameters.RemoveAt(ununsedParameterName);
});

The LINQ query that is been used for removing the unused parameters is removing the used command parameters. The result of
formatter.AssignedParameterNames are "?" for each parameter while the parameter names for cmd.Parameters are "p0, p1" thus
removing all the parameters used or unused for the query. As a temporary fix, I just commented-out the code above and NHibernate
can now successfully retrieve the records given a specified criteria. I think the problem is due to the SQL syntax of DB2 wherein all
parameters are represented with a question mark sign "?". I will also try to analyze the source code to find a solution to this bug.

Environment

None

Activity

Oskar Berggren May 30, 2012 at 6:31 PM

Closing issues fixed in 3.3.1.CR1.

Julian Maughan September 30, 2011 at 12:45 AM

Excellent. Thanks for confirming the issue is fixed.

percival evangelio September 29, 2011 at 11:32 PM

I've been testing the updated source code, it seems like the problem has been resolved since I don't encounter the said issue anymore. Thanks for the help.

Julian Maughan September 27, 2011 at 6:48 AM

The source code is hosted on GitHub and can be downloaded as a zip archive from there - see https://github.com/nhibernate/nhibernate-core.

Once you have downloaded it, there is a batch file called ShowBuildMenu that provides options for building the source code. Let me know if you have any difficulties.

percival evangelio September 27, 2011 at 6:41 AM

@Julian, may i know where can I download the latest source? It seems like the NHibernate-3.2.0.GA-src.zip in sourceforge has only been updated last 7/30/2011. I will test it right away (DB2 for iSeries) once I downloaded the updated source.

Fixed

Details

Assignee

Reporter

Components

Fix versions

Affects versions

Priority

Who's Looking?

Open Who's Looking?
Created September 19, 2011 at 12:03 AM
Updated May 30, 2012 at 6:31 PM
Resolved September 30, 2011 at 12:45 AM
Who's Looking?