Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 692913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:42:00+00:00 2026-05-14T02:42:00+00:00

For quite some time , I was reading about the optimistic concurrency in NHibernate.

  • 0

For quite some time , I was reading about the optimistic concurrency in NHibernate. If what i understood was correct then the below sample should hold good.

Consider two transactions T1 and T2.

  1. When T1 and T2 are done simultaneously , the state(DB entries) gets updated with the values of the most latest update.(T1 or T2).

Though it seems to be conceptually sound , how do i simulate this for the purpose of understanding and integration testing.?

Can someone help me with a sample c# code.?

Thanks ,

vijay

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:42:00+00:00Added an answer on May 14, 2026 at 2:42 am

    Now after a lot of googling , i have found out a fairly simple way to do that .The following are the steps to reproduce this.

    1. Have a Thread.Sleep() between the Get() and Update() methods, for only one user(process 1 ).

    2. When process 1 is running , start process 2 which doesnt encounter the Thread.Sleep() and completes the update before the process 1 does .

    3. Now process 2 has modified the data in the data base, now when process 1 tries to update the data, NHibernate throws a stale object exception.

    Please refer the following code snippet.

    public void Update(int empid)
        {
            Employee person = this.dalService.GetByEntityId(empid);
            person.Name = "Process 1";
    
            // At this point , Update the Person table  manually using raw sql query
            // such as this 'Update Person Set Name = 'Process 2'where empid = @empid;
    
    
            // When the update is performed , it is expected to throw the exception , as the in memory data
            // is different from the one in database.
            if (username.equals("Bob"))
            {
                Thread.Sleep(50000);
                // If this is a website, have the above condition, so that it is simulated only for one user.
            }
    
            this.dalService.Update(person);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been reading on this quite some time...and i'm puzzled - Can you help
Have spend quite some time to learn Sencha touch, just like an evaluation about
I am new to JavaScript and after reading related books for quite some time,
I have been at this for quite some time now, reading tutorials and so
I've been reading this for quite some time but doesn't make sense to me..
Quite some time i`ve learnt MVC. I have seen various techniques to post data
quite some time ago i noticed that in Visual C++ 10 ADL fails when
This question was asked quite some time ago, and while it covers possible solutions
Recently I spent quite some time writing various Visual Studio Extensions projects. Even though
My downloadFile AsyncTask may need quite some time in case of concurrent downloads over

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.