Null id in the entry "MyEntityType" (do not clear the session after an exception has occurred) when trying Session.GetAll after a GenericADOException exception

I will catch a GenericADOException with InnerException.Message = "Unique key violation ..." to inform the user that the entered login is already in use.
after that I try to get some date (Session.CreateCriteria), I get this error: null id in the entry "MyEntityType" (do not clear the session after an exception occurs)

+7
c # nhibernate
source share
2 answers

http://www.nhforge.org/doc/nh/en/index.html#manipulatingdata-exceptions

If ISession throws an exception, you must cancel the transaction immediately, call ISession.Close () and drop the ISession instance. Certain ISession methods will not leave a session in a consistent state.

Did you select a session after exclusion and start a new session?

+7
source share

You can remove the object from the context and continue if you follow these steps:

public void Save() { try { Session.SaveOrUpdate(this); } catch { // If the object as a null identifier everything else fails. Remove from context if (Session.GetIdentifier(this) == null) ((SessionImpl)Session).PersistenceContext.EntityEntries.Remove(this); throw; } } 
+2
source share

All Articles