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.  [ 4 posts ] 
Author Message
 Post subject: New Session after error occurs
PostPosted: Thu Jul 05, 2007 2:45 am 
Beginner
Beginner

Joined: Tue May 29, 2007 3:14 am
Posts: 28
I've got a problem. If an nhibernate-error occurs, I perform a rollback. But after this it's not possible to use the current session but I also don't want to restart the program. How can I create a new session?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 05, 2007 3:08 am 
Newbie

Joined: Wed Jul 04, 2007 5:31 pm
Posts: 17
>
> I've got a problem. If an nhibernate-error occurs, I perform a rollback.
> But after this it's not possible to use the current session but I also don't
> want to restart the program.


You have to Close session after Rollback. Even more - you have to close session after hibernate exceptions. Closing supposed to cleanup all the mess that caused exception and it will make all your objects Detached. To reattach these objects to newly opened session you can:
- call Session.update(detached_object) if your detached object is modified
- or call Session.lock if your detached object is not modified.

> How can I create a new session?

Well, do it the same way as you opened first session:)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 05, 2007 3:25 am 
Beginner
Beginner

Joined: Tue May 29, 2007 3:14 am
Posts: 28
I already tried it in this way, but it seemed that this does not work. I found an other error which was the problem...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 05, 2007 3:25 am 
Newbie

Joined: Wed Jul 04, 2007 5:31 pm
Posts: 17
to check if object is attached to session - call Session.Contains(obj)


To avoid "Contains, Update/Lock" sequence and minimize working
with Detached objects - you can consider "designing away" from
nhibernate-errors. I.e. try to make sure that they won't happen in
a first place. And when they happen that will mean that something
unpredictable (and possible unrecoverable:)) happened.


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