Hibernate Books

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Using nHibernate session in webpage
PostPosted: Wed Jun 06, 2012 9:00 am 
Newbie

Joined: Tue Aug 31, 2010 3:40 am
Posts: 2
Hi,

I got a web solution (aspx) that uses nHibernate.

Im using the same nHibernate session for all users that means i only create one session and then reuse it.

My problem is when i have the same object open in two different tabs in ex. Crome when i update the object on one of the pages i get the
"a different object with the same identifier value was already associated with the session"

My update function looks like this now:
public virtual void Update(object entity)
{
ValidateSession();
if (entity == null)
return;

var ownTrans = !Session.Transaction.IsActive;
if (!Session.Transaction.IsActive)
Session.Transaction.Begin();
try
{
Session.SaveOrUpdate(entity);
if (ownTrans)
{
Session.Transaction.Commit();
}
}
catch (Exception exp)
{
if (ownTrans)
Session.Transaction.Rollback();
throw (exp);
}
}

Any ideas to what i have done wrong?

Regards,
Jacob


Top
 Profile  
 
 Post subject: Re: Using nHibernate session in webpage
PostPosted: Sat Jun 09, 2012 6:20 am 
Newbie

Joined: Sat Jun 09, 2012 6:03 am
Posts: 1
Location: Honolulu
I believe that you will have to evict the object from the session it was loaded in before that session is closed.

_________________
http://www.bestfakedoctornotes.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.