I've setup a trivial table of two integers, and am trying this code on it
SimpleTable sm1 = (SimpleTable)session.Load(typeof(SimpleTable), 1);
MessageBox.Show(sm1.Id.ToString());
SimpleTable sm2 = (SimpleTable)session.Load(typeof(SimpleTable), 3);
MessageBox.Show(sm2.Id.ToString());
First call works fine, the second fails with the exception
"could not load object"
{"Invalid index 0 for this OleDbParameterCollection with Count=0." }
Is this a reasonable thing to attempt ? Or should I be using a new session for pretty much every query ?
I'm using nhibernate-0.8.2.0 with
NHibernate.Dialect.SybaseDialect
NHibernate.Driver.OleDbDriver
Provider=Sybase.ASEOLEDBProvider;Server ....and so on
Looking at the code, it appears to be an issue with the way commands are cached in BatcherImpl.cs. The sequence of events is
BatcherImpl.cs creates a new command for the sql
The command has a param created on it for the id number I send in
The command is stored in a hashtable called commands in BatcherImpl.cs
Loader.cs executes the command, and processes the results
Loader.cs calls CloseQueryCommand
This essentially calls Dispose() on the command - which amongst other things erases the parameter from it
Next time I call session.Load on the same table, it retrieves the command from the cache in BatcherImpl.cs and tries to use it. It fails when it tries to setup the parameter bindings, because the command no longer has a parameter in it. Even if this weren't the case, I don't think the command can be reused after Dispose() has been called on it.
If this is a genuine problem, I guess that either Dispose shouldn't be called on the command, or the command should be removed from the commands hashtable as part of CloseQueryCommand
|