0

デスクトップ アプリケーションと Web アプリケーションによって参照される共通の dll があります。メソッドの 1 つは、3 つのオブジェクトを作成し、それらをトランザクション内で DB に挿入します。

ただし、このメソッドを Web アプリケーションとデスクトップ アプリケーションから同時に呼び出すと、オブジェクトは 3by3 では挿入されません...それらの順序は混合されます (デスクトップ アプリケーションから 1 つ、次に Web アプリケーションから 1 つなど)。

私のコードは大丈夫ですか?マッピングや 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();
               }
4

1 に答える 1

1

1 つのトランザクションで挿入を実行すると、他の同時トランザクションで挿入が行われないという誤った仮定に基づいています。

これは真実ではありません(特定のトランザクション分離レベルを使用したり、テーブル全体を排他的にロックしたりしない限り...しかし、それは真実ではないとだけ言っておきましょう)

于 2013-03-29T18:10:32.150 に答える