NHibernate 3 session state after rollback()?

According to when a bernate Session throws an exception, you must close the Session and create a new one. Also, when you roll back a you must not later commit it or flush the Session - you must start over in a new Session.

According to when a bernate Session throws an exception, you must close the Session and create a new one. Also, when you roll back a you must not later commit it or flush the Session - you must start over in a new Session. In particular (and this is an implementation detail so don't rely on it), after a rollback, the bernate Session still has entities created/modified since the transaction began - bernate doesn't go through your entities and revert all changes you made.

Therefore, if you roll back the transaction and then flush the Session, bernate will commit entity changes that you thought you rolled back. If you are going to play with fire by trying to hack around this behavior (such as by clearing the Session), beware. It's best to just start over with a new Session.

1 Ok, but my session is contextual managed by structuremap ioc, and is per wcf call. If I dispose the session then I will have errors elsewhere. – Luka Dec 6 '10 at 17:26 What exceptions are you getting?

Can you try to prevent them? Can you post them here? – gdj Dec 6 '10 at 17:49 I am getting GenericAdoException , because I am trying to insert a duplicate value, that must be unique.

But that is not the point. I need to know what is the best practice. Until now I have exception handling like the one above.

But now, I am seeing that this will not be enough. – Luka Dec 6 '10 at 18:26 I can not predict every exception that can happen, I need to have exception handling, and I need to know what must I do so I don't get invalid data in db. – Luka Dec 6 '10 at 18:28 @Luka since you are using a session-per-call it would make sense to have a transaction-per-call (transaction-per-session).

This will serve the contextual unit-of-work where each call has no potential side-effects: if a query fails in a call, all db operations that were done in the call will be rollbacked. – Jaguar Dec 6 '107 at 8:29.

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