|
From: Steve B. (JIRA) <nh...@gm...> - 2011-06-11 14:43:05
|
[ http://216.121.112.228/browse/NH-2765?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Steve Bohlen closed NH-2765.
----------------------------
Resolution: Not an Issue
By design, once an exception is thrown in an operation on the ISession, the ISession is considered to be in an "inconsistent state" and thus CANNOT be used for further operations with any expectation of reliable results.
As you have discovered here, this does not mean you can't *call* methods on the ISession after an exception is raised, just that the ISession is not guaranteed to behave predictably after any exception is thrown during an op on it. Because of this behavior, the recommended pattern is to *discard* the current ISession once an exception is thrown, acquire a brand *new* ISession instance from the ISessionFactory, and perform any compensating/recovery logic in that new instance of the ISession.
Continuing to use/interact with an ISession instance once an exception has been thrown not support/contra-indicated.
You might consider the following pattern that (depending on your specific use-case) might permit you to react to the problem by simply rolling back an NH Transaction...
using (var tx = session.BeginTransaction())
{
try
{
//some behavior in here like...
session.SaveOrUpdate(myObject);
tx.Commit();
}
catch (Exception ex)
{
tx.RollBack();
throw;
}
}
> Session.Clear() doesn't work after exception occur.
> ----------------------------------------------------
>
> Key: NH-2765
> URL: http://216.121.112.228/browse/NH-2765
> Project: NHibernate
> Issue Type: Bug
> Components: Core
> Affects Versions: 3.2.0Beta1
> Reporter: mod sartawi
>
> Hi there,
> When I try to add record by call Session.Save(object), if the object's ID already exists in database I catch the exception then remove the object from the session by Session.Evict(object) or Session.Clear() then change the ID for the object then call again Session.Save(object) after this I notice 2 statement sent to database, one with old ID and other with new ID and this make exception again with old ID, and if do same and change ID again then call Save() 3 statement sent to database even after call Session.Clear(). this behavior I notice with version 3.2.0 Beta 1
> Thanks in advance.
> Regards,
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://216.121.112.228/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
|