Hi there, I am trying to run the following test code:
Code:
Dim s As NHibernate.ISession = HibernateFactory.GetSession
Dim t As NHibernate.ITransaction = s.BeginTransaction
Dim c As Customer = s.Get(GetType(Customer), 1)
c.NewSession()
c.CancelSession()
s.Save(c)
t.Commit()
s.Close()
The Customer class contains zero or more Sessions and looks like this:
Code:
Public Class Customer
Private mID As Integer
Private mCurrentSession As Session
Private mSessions As IList = New ArrayList
Public Property ID() As Integer
Get
Return mID
End Get
Set(ByVal Value As Integer)
mID = Value
End Set
End Property
Private Property Sessions() As IList
Get
Return mSessions
End Get
Set(ByVal Value As IList)
mSessions = Value
End Set
End Property
Public Sub NewSession()
mCurrentSession = New Session(Me)
mSessions.Add(mCurrentSession)
End Sub
Public Sub CancelSession()
mSessions.Remove(mCurrentSession)
End Sub
End Class
My mapping files for Customer and Session are as follows:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="WindowsApplication1.Customer, WindowsApplication1" table="customers">
<id name="ID" column="customerid">
<generator class="sequence">
<param name="sequence">customers_customerid_seq</param>
</generator>
</id>
<bag name="Sessions" inverse="true" cascade="all-delete-orphan" lazy="true">
<key column="customerID" />
<one-to-many class="WindowsApplication1.Session, WindowsApplication1" />
</bag>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="WindowsApplication1.Session, WindowsApplication1" table="sessions">
<id name="ID" column="sessionid" unsaved-value="0">
<generator class="sequence">
<param name="sequence">sessions_sessionid_seq</param>
</generator>
</id>
<many-to-one name="mParent" column="customerid" access="field" />
</class>
</hibernate-mapping>
When I try to run the test code though I get the following error message:
Quote:
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.
Could someone tell me what I am doing wrong?
Thanks very much.