-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: SQL insert, update or delete failed with inverse=true
PostPosted: Wed Oct 26, 2005 7:58 pm 
Newbie

Joined: Wed Oct 26, 2005 5:28 am
Posts: 7
Location: Australia
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.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 26, 2005 9:26 pm 
Newbie

Joined: Wed Oct 26, 2005 5:28 am
Posts: 7
Location: Australia
As a side note, when I remove the inverse=true from the Customer mapping the code works fine. Obviously this is less efficient though because NHibernate has to issue an INSERT statement and an UPDATE statement when new Sessions are added to a Customer instead of just one INSERT statement.

Does anyone know what I am doing wrong when I have inverse=true?

Kind regards,

Brad


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 27, 2005 10:31 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Read:
NHibernate Documentation - Example: Parent/Child
www.hibernate.org - Inside explanation of inverse=true

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.