Hello,
I am using VB.NET w/ .NET 1.1 and MSSQL 2000 and NHibernate 1.0.3. I'm trying to cope with columns that allow nulls, in my particular case it's an integer column. It's defined in my .hbm.xml file like this:
Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="NHibernateTest.NHibernateTestClass, NHibernateTest" dynamic-update="true" table="NHibernateTestTable" optimistic-lock="dirty">
<id name="Seq" type="Int32">
<generator class="identity" />
</id>
<property name="NullableInt" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate" not-null="false" />
</class>
</hibernate-mapping>
In my VB.NET class the property is defined as:
Code:
Private _NullableInt As Nullables.NullableInt32
Public Property NullableInt() As Nullables.NullableInt32
Get
Return _NullableInt
End Get
Set(ByVal Value As Nullables.NullableInt32)
_NullableInt = Value
End Set
End Property
I have inserted one row into this table, which contains a NULL in the NullableInt column. It loads my one entry from the database table just fine, then I set the value of the NULL property to 0:
Code:
Dim test As NHibernateTestClass = CType(session.Load(GetType(NHibernateTestClass), 1), NHibernateTestClass)
Debug.Assert(Not test.NullableInt.HasValue)
test.NullableInt = New Nullables.NullableInt32(0)
Debug.Assert(test.NullableInt.HasValue)
session.Flush()
... but after I flush the session, I see the following generated SQL:
Code:
NHibernate: UPDATE NHibernateTestTable SET NullableInt = @p0 WHERE Seq = @p1 AND NullableInt=@p2
@p0 = '0'
@p1 = '1'
@p2 = ''
This fails - because it should be testing in the WHERE clause that "NullableInt IS NULL" - right?
Then the exception occurs:
Code:
An unhandled exception of type 'NHibernate.HibernateException' occurred in nhibernate.dll
Additional information: SQL insert, update or delete failed (expected affected row count: 1, actual affected row count: 0). Possible causes: the row was modified or deleted by another user, or a trigger is reporting misleading row count.
I understand why the exception is occuring, it just doesn't make any sense to my what the generated UPDATE statement is not looking like what I expect. Can anyone tell me what I should do or look at in order to investigate this?
Thanks!
David McClelland