Hi,
I am working on a sample page where I want my page to setup my table and then fill my database with some starter data. After this root nodes will be added to a TreeView and using the TreeNodePopulate event further queries will be sent to the database and the tree updated. I also have a button to remake the database tables and repopulate the treeview with rootnodes.
For this I use the well known NHibernateHttpModule by Benday to setup the factory and provide sessions.
The strange thing is that the expanding of the treeview goes fine, the resetting of the database too. But when I expand a root node and thereafter resetting the database it complains about a unique key contraint violation. This leads me to believe that somehow retrieving child nodes of an expanding node causes a database reset on the next request to not actually go through causing:
Code:
NHibernate.NonUniqueObjectException was unhandled by user code
Message="a different object with the same identifier value was already associated with the session: 1, of class: Symtech.Concept.Logic.BusinessUnit"
Source="NHibernate"
StackTrace:
at NHibernate.Impl.SessionImpl.CheckUniqueness(Key key, Object obj)
at NHibernate.Impl.SessionImpl.DoSave(Object theObj, Key key, IClassPersister persister, Boolean replicate, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything)
at NHibernate.Impl.SessionImpl.DoSave(Object obj, Object id, IClassPersister persister, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything)
at NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything)
at NHibernate.Impl.SessionImpl.Save(Object obj)
at NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj)
at Symtech.Concept.DataAccess.BusinessUnitHandler.Save(BusinessUnit bu) in D:\projecten\Symtech.Concept\DataAccess\BusinessUnitHandler.cs:line 45
at Symtech.Concept.DataAccess.SchemaCreator.CreateSchema() in D:\projecten\Symtech.Concept\DataAccess\SchemaCreator.cs:line 25
at _Default.btnSchema_Click(Object sender, EventArgs e) in d:\projecten\Symtech.Concept\WebUI\Default.aspx.cs:line 49
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
The code executed:
Code:
public static void CreateSchema()
{
SchemaUtility.ExportSchema();
BusinessUnit root = new BusinessUnit();
root.Name = "Symphony Technology";
BusinessUnit dev = new BusinessUnit();
dev.Name = "Sofware Development";
root.AddDevision(dev);
BusinessUnit ond = new BusinessUnit();
ond.Name = "Customer Support";
root.AddDevision(ond);
BusinessUnit sen = new BusinessUnit();
sen.Name = "System Engineering";
root.AddDevision(sen);
BusinessUnitHandler.Save(root);
}
Once again this code works fine untill I expand a node before it causing this to run:
Code:
protected void tvwBusinessUnits_TreeNodePopulate(object sender, TreeNodeEventArgs e)
{
TreeNode parent = e.Node;
// Children ophalen van deze treenode
IList children = BusinessUnitHandler.Devisions(int.Parse(parent.Value));
// Node vullen
foreach (BusinessUnit bu in children)
{
TreeNode tn = new TreeNode();
tn.PopulateOnDemand = true;
tn.Text = bu.Name;
tn.Value = bu.Id.ToString();
parent.ChildNodes.Add(tn);
}
}
Does anyone have the slightest idea why this would go wrong? It looks like something causes the generation of a wrong Id, but expanding a node as the cause seems so weird to me...