-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Object in session
PostPosted: Fri Dec 09, 2005 11:25 pm 
Newbie

Joined: Sun Nov 27, 2005 2:31 pm
Posts: 12
Location: Dublin
hajo,

is it possible to find out if object is associated with any session or not?

thanks in advance for info

Pawel Pabich


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 10, 2005 5:29 am 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
Since the object itself is something that you made it won't know about any session it's associated with unless you explicitly coded in a reference to the session (you can use ILifecycle callbacks to do this if you really want to).

You can find out whether the object is associated with a specific session by asking the session whether it contains the entity. To do this use session.Contains([entity]).

Hope that helps,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 10, 2005 9:11 am 
Newbie

Joined: Sun Nov 27, 2005 2:31 pm
Posts: 12
Location: Dublin
Hajo, thanks for response

Yes I know but using hectorcruz's approach in Win Forms:
http://nhibernate.sourceforge.net/forum/viewtopic.php?t=302&postdays=0&postorder=asc&start=15
I get an exception that PersistenCollection can not be assigned to 2 sessions therefore before I call ISession.Lock() I would like to check If collection (bag or set) is or is not associated with any session. I thought that maybe there is some global API like ISessionFactory.IsBoundToSession(object) or something that will allow me to retrive this information. Do you see any workaround?

Pawel Pabich


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 10, 2005 10:01 am 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
Sorry - that was the best I could do!

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 12, 2005 9:14 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Not with "any" session, but you can use ISession.Contains(obj) to find out whether an object is associated with this session. It doesn't work on collections though.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 12, 2005 10:26 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Pawel Pabich wrote:
I thought that maybe there is some global API like ISessionFactory.IsBoundToSession(object) or something that will allow me to retrive this information.


What would you do with this information?

IMO, whenever you have two opened sessions in which you want to use your entities, then something is going wrong...

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.