I have a property defined in my HBM file like this:
<property name="OwnerId" column="OwnerID" type="System.Int32" not-null="false" />
It is defined as a nullable field in the database also. If a record in the DB has the OwnerID column set to an integer, this object is correctly loaded by NHibernate. But if the record has it set to null, NHibernate bombs with seemingly random errors including:
1) Column name 'ModuleAnchorID' appears more than once in the result column list:
[SqlException (0x80131904): Column name 'ModuleAnchorID' appears more than once in the result column list.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +925466
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +800118
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +186
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1932
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +149
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1005
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +149
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +135
NHibernate.Impl.NonBatchingBatcher.AddToBatch(IExpectation expectation) +35
NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Object[] oldFields, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session) +1055
2) not-null property references a null or transient value:
[PropertyValueException: not-null property references a null or transient value:]
NHibernate.Impl.SessionImpl.CheckNullability(Object[] values, IEntityPersister persister, Boolean isUpdate) +224
NHibernate.Impl.SessionImpl.FlushEntity(Object obj, EntityEntry entry) +1019
NHibernate.Impl.SessionImpl.FlushEntities() +182
NHibernate.Impl.SessionImpl.FlushEverything() +90
NHibernate.Impl.SessionImpl.AutoFlushIfRequired(ISet querySpaces) +64
NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria, IList results) +217
NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria) +42
NHibernate.Impl.CriteriaImpl.List() +29
Is OwnerID a reserved field name that is somehow confusing NHibernate?