Hello All,
I have an issue. I have two users trying to update same data at same time may be milliseconds apart. The issue is I dont want second user data who might have old on the form than in the database to overwrite the user1 data. So if the form doesnt has the latest data loaded from database. I will error out the user. So user 1 click submit to save data and in my service layer I update a column to track some has updated the data recently (with dtm field for the master record) , this dtm field is sent to form as well to track the last update dtm. Now second user tries to save it it should error out but allow user1 to save data. The first step in my service layer is to update the updatedtm but looks like hibernate is not getting the latest data for user 2 even I am update the data in a separate transaction than the main transaction and using flush. for Below methods we use spring for transactions and i have mentioned propagation level as requires_new for saveAccount method. But looks like I am still getting old data. I have broken the save in to two methods because hibernate has flush mode on commit.
ex:
Code:
public void saveUser(Form form)
{
Account account = retriveAccount(id);
//compare date from db with form date if successful saveAccount else error out
saveAccount(account);
//do some business logic below
}
public void saveAccount(Account account){
accountDao.save(account);
accountDao.flush();
}