Friday, June 03, 2005

NHibernate ICriteria.SetFetchMode() issue.

I think I might have solved it? It's sloppy, and frankly, might be causing other bugs, but it seems to work for me, so until it's officially resolved, I think I'll stick to it if I don't run across anything broken by it.

The solution was on line 313 in NHibernate.Loader.Loader.cs:

int count;
for ( count = 0; count < maxRows && rs.Read(); count++ )
{
object result = GetRowFromResultSet( rs, session, queryParameters, hydratedObjects, optionalObject, optionalId, keys, returnProxies );
results.Add( result );
}


As you can see, each row in the resultSet results in an object reference in the results IList. This is obviously no-bueno.

So I modified it to this:

int count;
for ( count = 0; count < maxRows && rs.Read(); count++ )
{
object result = GetRowFromResultSet( rs, session, queryParameters, hydratedObjects, optionalObject, optionalId, keys, returnProxies );
if(!results.Contains(result)) {
results.Add( result );
}
}


And now you see the hackiness. Basically this will prevent you from getting a list with duplicate objects in it.

Now I can't think of why you'd want that off the top of my head, but it does seem a huge change to be making, so I dunno. I'm anxious to see what the real solution is the NHibernate guys come up with...
Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?