Im getting this exception when calling my update DAO method.
NHibernate.HibernateException: Illegal attempt to associate a collection with two open sessions.
Im getting an object with this:
Code:
protected Object get(Object ob,int id)
{
try
{
ISessionFactory factory = NHibernateSessionFactory.getFactory();
ISession session = factory.OpenSession();
return session.Get(ob.GetType(),id);
}
finally
{
if(session != null)
session.Close();
}
}
Then im up dateing it like this:
Code:
private void subButton_Click(object sender, System.EventArgs e)
{
String id = Request.QueryString.Get("Id");
FairDAO fairDAO = new FairDAO();
Fair f = fairDAO.get(id);
f.Code=Convert.ToInt32(id);
f.Description=desp.Text;
f.StartingDate = new DateTime( Convert.ToInt32(dateY.Text),
Convert.ToInt32(dateM.Text),
Convert.ToInt32(dateD.Text));
f.Duration=Convert.ToInt32(duration.Text);
f.Title=title.Text;
f.SponsorCode=Convert.ToInt32(sponsor.Text);
fairDAO.updateFair(f);
Response.Redirect("staffAdmin.aspx");
}
and then persisting it like this:
Code:
protected void update(Object o)
{
try
{
ISessionFactory factory = NHibernateSessionFactory.getFactory();
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction();
session.Update(o);
transaction.Commit();
session.Close();
}
catch
{
if(transaction != null)
transaction.Rollback();
throw;
}
finally
{
if(session != null)
session.Close();
}
}
I cant see how here is 2 open sessions, im closeing the sessions, and dedugging in VS Confirms this