-->
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.  [ 5 posts ] 
Author Message
 Post subject: Problem with Session.Delete(object)
PostPosted: Wed Apr 11, 2007 11:14 am 
Newbie

Joined: Mon Apr 09, 2007 10:29 am
Posts: 14
I have called Session.Delete(object) and it threw an exception(a valid exception due to some foriegn key constrained). I catched the exception and then did Session.Rollback(). Then the problem occurs that everytime i call the list of the above type objects in the same session it gives me the same exception(not able to delete object due to foreign key constraint).

Only solution that works is Session.Clear() which i dont want to call as i want to use some of the data which is maintained by Session.

Thanx in Anticipation
Saurabh


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 11, 2007 5:19 pm 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
I believe that the recommended approach is that when a session throws an exception you should close the session and open a new one.

Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 12, 2007 4:41 am 
Newbie

Joined: Mon Apr 09, 2007 10:29 am
Posts: 14
But in that case we wont be able to use the lazy loading on the object previously made. Also when i query about other objects the session works fine except the object the type when the error is thrown.

Saurabh


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 13, 2007 1:55 am 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
@Saurabh -
I don't get your second comment, but you can reattach objects using session.Lock to reattach your previously created proxy objects to the new session after you rolled back the transaction.
MIKE

_________________
If this helped...please remember to rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 25, 2007 4:53 am 
Regular
Regular

Joined: Wed Apr 25, 2007 4:18 am
Posts: 51
Location: Belarus, Gomel
mnichols wrote:
you can reattach objects using session.Lock to reattach your previously created proxy objects to the new session


Is there a simple way to find ALL proxies, existed in session before exception?

Now we use a single permanent session in out app (WinForms) and we may have a bunch of proxies. We use static Repository class and underlying PersistentManager class (a kind of SessionFactory+Session wrapper) to encapsulate all NHibernate stuff, so it seems to be reasonable to add session recreation and proxies rebinding code to this layer - after each transaction rollback in catch blocks.

BTW maybe there is some opportunity to get rid of permanent session without loosing lazy load capabilities? Maybe a sort of proxy access interception or LazyInitializationException handling - to reattach proxy to session, perform it's initialization and then disconnect?
Please forgive if it is are a stupid question, I'm just a newbie to all this stuff...

_________________
WBR, Igor


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