NHibernate 2.0 MultiCriteria and doc bugs....

"Brian Chavez" <[email protected]> Fri, 29 Aug 2008 14:25:04 -0700
Newsgroups gmane.comp.windows.dotnet.nhibernate.devel
Message-ID <007d01c90a1d$b4e25170$1ea6f450$@com>
Hi there,

 

**********

Bug 1) First and most important, is a bug (I think) in NHibernate's
MultiCriteria:GetResultsFromDatabase() implementation.  RowCount Criteria is
order dependent when using MultiCriteria.  I think it's expected that the
order in which you add RowCount criteria to MultiCrtieria should not matter.

 

For example:

 

var searchCriteria = session.CreateCriteria(typeof(Foo));

 

var countCriteria = CriteriaTransformer.TransformToRowCount( searchCriteria
);

 

//Failure

var results = session.CreateMultiCriteria()

             .Add(searchCriteria)

             .Add(countCriteria)

             .List();

 

Fails to return the row count in results[1];  However, if you change the
order like this:

 

//Success

var results = session.CreateMultiCriteria()

              .Add(countCriteria)

              .Add(searchCriteria)

              .List();

 

Adding countCriteria first successfully works and results[0] has the correct
row count.

 

In the failed case, I think there is an extra reader.Read() being executed
probably from the for loop initialization inside
GetResultsFromDatabase():Line 199: "for(count = 0; count < maxRows &&
reader.Read()...)" advances the reader+1 in for initialization, which puts
the data reader cursor out of the row count and causes the loop to terminate
prematurely.

 

**********

Bug 2) MultiCriteria debug output not printing

 

Line 73 in MultiCriteriaImpl.cs: log.DebugFormat("Query #{0}: {1}", i,
criteriaQueries[i]);

 

Format parameter {1} is always string.Empty.  So, no debug output is printed
besides "Query #n"

 

**********

Bug 3) There are problems with MultiCriteria documentation.

 

According to: http://www.nhforge.org/doc/nh/en/

 

In Section 16.8, there is a bug in the first sample code.  Using
(long)((IList)results[1])[0] to cast the row count into long fails because
the underlying type is int.  results[1][0] returns object type (with
underlying int), and cannot unbox+cast at the same time, or you'll get
"Specified cast is not valid."

 

Also, just to check, if the # of rows exceeds int.MaxValue, will the
underlying results[1][0] return type be long (and not int)?  If not, then
there's a possible bug here too with row count.

 

In Section 16.8, there is no such thing as "CollectionHelper.ToArray<>"
method.

**********

 

These are some issues I see at first glance.  If you could point me to some
guidance on /readme on how to setup the unit tests, I would be glad to
submit unit tests for Bug 1 and Bug 2.

 

Thanks,

Brian

 


----------------------------------------------
Brian Chavez
Bit Armory, Inc.
 <http://www.bitarmory.com> http://www.bitarmory.com

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/

_______________________________________________
Nhibernate-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nhibernate-development