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.
Have a Thread.Sleep() between the Get() and Update() methods, for only one user(process 1 ).
When process 1 is running , start process 2 which doesnt encounter the Thread.Sleep() and completes the update before the process 1 does .
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);
}