NHibernate version:
1.2.0
Mapping documents:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="AgCg.ContentManagement.Domain.ContentBase, AgCg.ContentManagement" table="Content">
<id name="id" access="field" type="Guid" column="Id">
<generator class="assigned" />
</id>
<discriminator column="ClassName" />
<property name="title" access="field" column="Title" />
<property name="text" access="field" column="Text" />
<property name="dateCreated" access="field" column="DateCreated" />
<property name="lastModified" access="field" column="LastModified" />
<property name="hitCount" access="field" column="HitCount" />
<subclass name="AgCg.ContentManagement.Domain.Menu, AgCg.ContentManagement">
<list access="field" name="children" cascade="all-delete-orphan" table="ContentRel">
<key column="ParentId" />
<index column="Position" />
<many-to-many class="AgCg.ContentManagement.Domain.ContentBase, AgCg.ContentManagement" column="ChildId"/>
</list>
</subclass>
<subclass name="AgCg.ContentManagement.Domain.Story, AgCg.ContentManagement" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
[Test]
public void TestStoryMapping()
{
User jim = new User("jim bob");
Menu menu = Menu.CreateTopLevelMenu("some menu", "some text", jim);
ISession session = factory.OpenSession();
Story story = menu.CreateChildStory("some story", "some story text", jim) as Story;
session.Save(menu);
session.Flush();
session.Delete(menu);
session.Flush();
session.Dispose();
}
Full stack trace of any exception that occurs:
Demo.Tests.Integration.MappingFixture.TestStoryMapping : NHibernate.StaleStateException : Unexpected row count: 0; expected: 1
at NHibernate.AdoNet.Expectations.BasicExpectation.VerifyOutcomeNonBatched(Int32 rowCount, IDbCommand statement)
at NHibernate.Impl.NonBatchingBatcher.AddToBatch(IExpectation expectation)
at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Object[] oldFields, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Boolean hasDirtyCollection, Object[] oldFields, Object oldVersion, Object obj, ISessionImplementor session)
at NHibernate.Impl.ScheduledUpdate.Execute()
at NHibernate.Impl.SessionImpl.Execute(IExecutable executable)
at NHibernate.Impl.SessionImpl.ExecuteAll(IList list)
at NHibernate.Impl.SessionImpl.Execute()
at NHibernate.Impl.SessionImpl.Flush()
at Demo.Tests.Integration.MappingFixture.TestStoryMapping() in c:\SVN\AgCg\Demo.Tests.Integration\Source\MappingFixture.cs:line 79
Name and version of the database you are using:
MySQL 5.0
The generated SQL (show_sql=true):
NHibernate: INSERT INTO Content (Title, Text, DateCreated, LastModified, HitCount, ClassName, Id) VALUES (?p0, ?p1, ?p2, ?p3, ?p4, 'AgCg.ContentManagement.Domain.Menu', ?p5); ?p0 = 'some menu', ?p1 = 'some text', ?p2 = '9/1/2007 2:47:19 PM', ?p3 = '9/1/2007 2:47:19 PM', ?p4 = '0', ?p5 = '765c96f1-b3ac-4fa8-8121-4c1be6d21ade'
NHibernate: UPDATE Content SET Title = ?p0, Text = ?p1, DateCreated = ?p2, LastModified = ?p3, HitCount = ?p4 WHERE Id = ?p5; ?p0 = 'some story', ?p1 = 'some story text', ?p2 = '9/1/2007 2:47:19 PM', ?p3 = '9/1/2007 2:47:19 PM', ?p4 = '0', ?p5 = '5bee058c-8663-4ff1-b51c-d0de0f25b553'
If I save a story object by itself it works fine, same deal with a menu object, but if I try to save a menu containing a story, it fails.
I noticed in the sql above that there is an UPDATE issued for the story, when I am expecting an INSERT.
I am using an assigned generator for the id on the base class (for both story and menu).
I realize this post is similar to
http://forum.hibernate.org/viewtopic.ph ... eexception, but I feel that I have a different case in that I can't provide an unsaved-value attribute since my domain objects generate the guids I'm using as ids.
Thanks for your help.
Robert