Hi everyone, I've been battling with this issue for a couple of days now.
I have a couple of classes in a many-to-many relationship, configured like so:
<class name="Entry" table="Entries">
<id name="Id" column="Id">
<generator class="native" />
</id>
<timestamp name="LastUpdated" column="Entry_LastUpdated" generated="always" />
...
<bag name="Sections" generic="true" table="EntrySections" inverse="false" cascade="none">
<key column="EntrySection_EntryId" />
<many-to-many column="EntrySection_SectionId" class="Blogs.BusinessLogic.Section, Blogs.BusinessLogic"/>
</bag>
</class>
<class name="Section" table="Sections">
<id name="Id" column="Id" unsaved-value="0">
<generator class="native" />
</id>
<timestamp .../>
...
<bag name="Entries" generic="true" table="EntrySections" inverse="false" cascade="none">
<key column="EntrySection_SectionId" />
<many-to-many column="EntrySection_EntryId" class="Blogs.BusinessLogic.Entry, Blogs.BusinessLogic"/>
</bag>
</class>
It is configured in a way that I could delete, say, a Section
object and its associations to any entries will be removed.
However, when I wish to only remove the associations, for example:
entry.Sections.Remove(section);
This is the only action I perform on this object. However, when the session flushes, the following StaleObjectStateException exception is thrown:
Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [Project.BusinessLogic.Entry#22]
I've been toying with the inverse
and cascade
values and googling for answers, but cannot find any solution. Neither inverse="true"
nor cascade="all/all-delete-orphan"
did the trick.
Is this a problem related to the many-to-many relationship, or am I looking in the wrong direction?
Are my classes mapped incorrectly?
Edit
Could this be an issue resulting from the way NHibernate works with the and the DateTime struct?