Nhibernate: Handling an ITransaction Exception So That New Transactions Can Continue with same ISession?

It's not possible to re-use an Nbernate session after an exception is thrown Quoting the documentation.

It's not possible to re-use an Nbernate session after an exception is thrown. Quoting the documentation: If the ISession throws an exception you should immediately rollback the transaction, call ISession.Close() and discard the ISession instance. Certain methods of ISession will not leave the session in a consistent state.So the answer is that you can't do what you're trying to do.

You need to create a new session and re-try the updates there.

Thanks for the response. Just wanted to make sure it's done right. What you're saying is that my error handling should be simply changed to: foreach (var pce in pces) { try { DALC.

UpdateOrAddObject(pce); } catch (Exception ex) { Console. WriteLine("Could not add Corporate Entity ID " + pce.CorporateEntity. CorporateEntityID.ToString()); session.Close(); session = sessionsManager.GetSession(); DALC.

Session = session; } } Looks like this works just fine. Thanks.

From what you posted, that looks like it will work. It really depends on the implementation of your DALC class. – Sean Carpenter Feb 3 '09 at 3:11.

I clear the session and it continues normally ISession session = NSession; using (ITransaction transaction = session. BeginTransaction()) { try { session. Update(user, user.

UserID); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); session.Clear(); throw new DALException("Cannot update user", ex); } }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions