-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate multiple users updating same data
PostPosted: Fri Mar 20, 2015 2:51 pm 
Newbie

Joined: Fri Mar 20, 2015 2:29 pm
Posts: 1
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();
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.