Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1089819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:16:51+00:00 2026-05-16T23:16:51+00:00

Hl Guys, I am busy writing a backend administrative program for a system that

  • 0

Hl Guys,

I am busy writing a backend administrative program for a system that exists. I have selected NHibernate for my data access solution and am fairly new to it. I am experiencing the following error in a parent/child relationship:

NHibernate.StaleStateException : Unexpected row count: 0; expected: 1

This error is caused by the fact that in my source code I add the new child object into the parent’s children collection of MeetingAdministrators. When I save the parent object I expect the children to be added as well, however an INSERT is generated only for the parent object. Nhibernate does not generate an INSERT for the child but instead attempts to UPDATE the child even though it does not exist. Thus it brings up the error message shown above. I have looked everywhere on the web and nhibernate documentation for this scenario but have not found any help. Most code involves foreign keys that are not part of the primary key, or people seem to be dealing with one-to-one or many-to-many relationships. I need to specify the mapping and code so that on insert of the parent, the children get inserted as well. Please help.

My data structure is as follows:

Meeting – parent table

  • MeetingID (pk) (int, identity)
  • Description
  • StartDate
  • IsActive
  • Venue

MeetingAdministrator – child table

  • MeetingID (pk, fk)
  • AdminNetworkID (pk) (varchar)
  • DateCreated
  • IsActive

And here is the Visual Basic .NET source:

<Serializable()> _
Public Class MeetingAdministrator

    Private _MeetingID As Integer
    Public Overridable Property MeetingID() As Integer
        Get
            Return _MeetingID
        End Get
        Set(ByVal value As Integer)
            _MeetingID = value
        End Set
    End Property

    Private _AdminNetworkID As String
    Public Overridable Property AdminNetworkID() As String
        Get
            Return _AdminNetworkID
        End Get
        Set(ByVal value As String)
            _AdminNetworkID = value
        End Set
    End Property

    Private _IsActive As Byte
    Public Overridable Property IsActive() As Byte
        Get
            Return _IsActive
        End Get
        Set(ByVal value As Byte)
            _IsActive = value
        End Set
    End Property

    Private _DateCreated As Date
    Public Overridable Property DateCreated() As Date
        Get
            Return _DateCreated
        End Get
        Set(ByVal value As Date)
            _DateCreated = value
        End Set
    End Property

    Private _LastModified As Date
    Public Overridable Property LastModified() As Date
        Get
            Return _LastModified
        End Get
        Set(ByVal value As Date)
            _LastModified = value
        End Set
    End Property

    Private _meeting As Meeting
    Public Overridable Property Meeting() As Meeting
        Get
            Return _meeting
        End Get
        Set(ByVal value As Meeting)
            _meeting = value
        End Set
    End Property

    Public Overrides Function Equals(ByVal obj As Object) As Boolean
        Return MyBase.Equals(obj)
    End Function

    Public Overrides Function GetHashCode() As Integer
        Return MyBase.GetHashCode()
    End Function

End Class




Imports Iesi.Collections
Imports Iesi.Collections.Generic



Public Class Meeting

    Private _MeetingID As Integer
    Private _Description As String

    Public Overridable Property MeetingID() As Integer
        Get
            Return _MeetingID
        End Get
        Set(ByVal value As Integer)
            _MeetingID = value
        End Set
    End Property

    Public Overridable Property Description() As String
        Get
            Return _Description
        End Get
        Set(ByVal value As String)
            _Description = value
        End Set
    End Property

    Private _StartDate As Date = Now
    Public Overridable Property StartDate() As Date
        Get
            Return _StartDate
        End Get
        Set(ByVal value As Date)
            _StartDate = value
        End Set
    End Property

    Private _IsActive As Byte
    Public Overridable Property IsActive() As Byte
        Get
            Return _IsActive
        End Get
        Set(ByVal value As Byte)
            _IsActive = value
        End Set
    End Property

    Private _DateCreated As Date
    Public Overridable Property DateCreated() As Date
        Get
            Return _DateCreated
        End Get
        Set(ByVal value As Date)
            _DateCreated = value
        End Set
    End Property

    Private _Venue As String
    Public Overridable Property Venue() As String
        Get
            Return _ Venue
        End Get
        Set(ByVal value As String)
            _ Venue = value
        End Set
    End Property

    Private _meetingAdministrator As ISet(Of MeetingAdministrator)
    Public Overridable Property MeetingAdministrators() As ISet(Of MeetingAdministrator)
        Get

            Return _meetingAdministrator
        End Get
        Set(ByVal value As ISet(Of MeetingAdministrator))
            _meetingAdministrator = value
        End Set
    End Property

    Public Overridable Sub AddAdministrator(ByVal meetingAdministrator As MeetingAdministrator)
        meetingAdministrator.Meeting = Me

        _meetingAdministrator.Add(meetingAdministrator)
    End Sub


    Public Sub New()
        _meetingAdministrator = New HashedSet(Of MeetingAdministrator)()

    End Sub
End Class

Here are the mapping files:

<!-- Meeting.hbm.xml -->
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Data"
                    namespace="Data.Domain" >

  <!-- Mapping Information -->
  <class name="Meeting"  table="Meeting" >
    <id name="MeetingID" column="MeetingID" type="int">
      <generator class="identity" />
    </id>
    <property name="Description" />
    <property name="StartDate" />
    <property name="IsActive" />
    <property name="Venue" />
    <set name="MeetingAdministrators" table="MeetingAdministrator" inverse="true"  lazy="true"  cascade="save-update"  access="property" >
      <key column="MeetingID"  foreign-key="MeetingID"  />
      <one-to-many class="Meeting"  />
    </set>
  </class>
</hibernate-mapping>

<!-- MeetingAdministrator.hbm.xml -->
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Data"
                    namespace="Data.Domain" >

  <!-- Mapping Information -->
  <class name="MeetingAdministrator"  table="MeetingAdministrator" >
    <composite-id>
      <key-property  name="AdminNetworkID"  column="AdminNetworkID"  type="string"  >
      </key-property>
      <key-many-to-one name="Meeting" class="Meeting" >
        <column name="MeetingID" />
      </key-many-to-one>
    </composite-id>
    <property name="IsActive" />
    <property name="DateCreated" />
  </class>
</hibernate-mapping>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:16:51+00:00Added an answer on May 16, 2026 at 11:16 pm

    I’m pretty sure you’ll need to add a <version/> property to your MeetingAdministrator class to have this working propertly. See this article for further discussion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.