2010-02-25 3 views

답변

7

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

(예외가 발생한 후 세션을 플러시하지 않음)

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.

예외가 발생한 후에 세션을 버리고 새로운 세션을 시작 했습니까?

+1

예외가 나는이 문제가 않을거야보다 던진 후 나는() Session.Clear를 할 경우, 하지만 예외가 발생한 단일 사용자로 인해 전체 웹 응용 프로그램에 대한 세션을 지우는 것이 좋습니다. – Omu

+1

예외가 발생한 후에 세션을 닫아야합니다. 나는 당신이 데이터베이스에 예외가 발생하지 않고 동일한 기능을 얻을 수 있도록 삽입하기 전에 로그인을위한 첫 번째 쿼리에 응용 프로그램을 다시 작성하는 것이 좋습니다. 구현 선택으로 인해 예외적 인 상황에서 현재 예외가 발생하고있는 것으로 보입니다. 또한 웹 요청 당 세션이 있어야하며 웹 응용 프로그램 당 세션이없는 것이 가장 좋습니다. –

1

당신은 컨텍스트에서 개체를 제거하고이 같이 할 경우 계속 사용할 수 있습니다 :

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; 
    } 
    } 
관련 문제