2013-03-29 19 views
0

我有桌面應用程序和Web應用程序引用的常見dll。其中一種方法創建3個對象,並將它們插入到事務中的DB中。NHibernate事務在Postgres上無法正常工作

但是,當我從Web應用程序和桌面應用程序同時調用此方法時,不會插入對象3by3 ...它們的順序是混合的(1從桌面應用程序,接着是1從Web應用程序等)。

我的代碼是否正常?是否有關於映射或nhibernate cfg的問題? 非常感謝您提前。

   Notifications not = new Notifications(); 
       not.Notes = applicationName; 
       not.GeneratedTime = DateTime.Now; 
       using (var session = SessionManager.OpenSession()) 
       using (var transaction = session.BeginTransaction()) 
       { 
        // do what you need to do with the session 
        session.Save(not); 

       not = new Notifications(); 
       not.Notes = applicationName; 
       not.GeneratedTime = DateTime.Now; 

        session.Save(not); 

       not = new Notifications(); 
       not.Notes = applicationName; 
       not.GeneratedTime = DateTime.Now; 

        // do what you need to do with the session 
        session.Save(not); 
        transaction.Commit(); 
       } 
+0

行的關係數據庫是不*** ***「排序」。它們的存儲順序完全不相關。只要確保在檢索數據時應用了合適的ORDER BY。這可以使用例如一個時間戳列,用於存儲行插入的時間。 –

回答

1

您有錯誤的假設,即在一個事務中執行插入操作將會阻止插入在其他併發事務中發生。

這是不正確的(除非你使用一些特定的事務隔離級別,獨佔鎖定整個表,等等......但讓我們只說這是不是真的)

+0

非常感謝,這有幫助。 – nanek