I have two simple classes with such mappings:
Code:
<class name="hibertest.ParentClass, hibertest" table="parent" >
<id name="Id">
<generator class="hilo" />
</id>
<property name="Name"/>
<bag name="Children" lazy="true" cascade="all" inverse="true">
<key column="pid"/>
<one-to-many class="hibertest.ChildClass, hibertest" />
</bag>
</class>
<class name="hibertest.ChildClass, hibertest" table="child" >
<id name="Id">
<generator class="assigned" />
</id>
<property name="Name"/>
<many-to-one name="ParentClass" class="hibertest.ParentClass, hibertest" column="pid" />
</class>
and code for work with objects:
Code:
ParentClass pc = (ParentClass) session.Load(typeof(ParentClass), 2);
ChildClass cc = new ChildClass();
cc.Name = "MyTest";
cc.Id = 6;
cc.ParentClass = pc;
pc.Children.Add(cc);
session.Flush();
Method session.Flush() causes exception:
Code:
Unhandled Exception: NHibernate.ADOException: could not synchronize database state with session ---> NHibernate.HibernateException: SQL update or deletion failed (row not found)
at NHibernate.Impl.NonBatchingBatcher.AddToBatch(Int32 expectedRowCount)
at NHibernate.Persister.EntityPersister.Update(Object id, Object[] fields, Boolean[] includeProperty, Object oldVersion, Object obj, SqlString sqlUpdateString, ISessionImplementor session)
at NHibernate.Persister.EntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Object[] oldFields, Object oldVersion, Object obj, ISessionImplementor session)
at NHibernate.Impl.ScheduledUpdate.Execute()
at NHibernate.Impl.SessionImpl.ExecuteAll(IList list)
at NHibernate.Impl.SessionImpl.Execute()
I can save objects only by session.Save(), but it is not convenient. Who was confronted with such problem help me, please
P.S. Cascade deletion works properly
Serega