I'm trying a very simple parent/child pattern with NHibernate with no luck.
The parent class:
public virtual string Id
public virtual string Name
pubic virtual ISet<Child> Children
the child class:
public virtual string Id
public virtual string Name
Child class has two public constructors:
One parameterless doing nothing
One with one parameter, assigning the Id
the hbm.xml file for parent:
<class name="Parent" table="parents">
<id name="Id" column="id">
<generator class="uuid.string"/>
</id>
<set name="Children" lazy="true" cascade="all" inverse="true">
<key column="parent"/>
<one-to-many class="Child"/>
</set>
<property name="Name" column="name"/>
</class>
the hbm.xml file for child:
<class name="Child" table="children">
<id name="Id" column="id">
<generator class="assigned"/>
</id>
<property name="Name" column="name"/>
</class>
Parent's constructor creates the list:
Children = new HashedList<Child>()
and I use the following code to save it (after opening the session and transaction)
Parent p = new Parent();
Child m = new Child("child_id");
p.Children.Add(m);
session.Save(p);
tx.Commit();
After doing this, the commit throws the exception. I thought it should be very easy to do this, but surprisingly there are no fully working examples of NHibernate 1.2 with C# generics around. All samples are partial.
Hibernate version:
1.2.1
Full stack trace of any exception that occurs:
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 NHibernate.Transaction.AdoTransaction.Commit()
at Onyaka.Website.Secure.Test.Page_Load(Object sender, EventArgs e) in C:\Projects\NET Projects\Onyaka\Web\Onyaka.Website\Secure\Test.aspx.cs:line 45
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Name and version of the database you are using:
MySQL 5.0
|