0

the timeline looks like this:

User(browser) ---------------------------> update TARGET 2----------------->

Thread ------> update TARGET 1 ---------> long_operation -----> update TARGET 3

I kick off a thread to execute an long_operation, and update the TARGET object before and after the operation.

The problem is, during the long_operation, the user could update the TARGET in UI. Therefore, when I try to update TARGET after long_operation, I get a optimistic lock exception.

I use version number to do optimistic locking, and update 2 is in a transaction.

I tried doing update 1 and 3 in different transaction -> doesn't work. I also tried update the version number before doing update_3 -> doesn't work.

Not sure what is the right thing to do here....

user2628641
  • 2,035
  • 4
  • 29
  • 45

1 Answers1

0

I get what I did wrong.

I need to evict the TARGET object from the cache and reread it from database to get the latest version before doing update_3.

before I was updating the "old" TARGET, therefore getting optimistic lock exception.

user2628641
  • 2,035
  • 4
  • 29
  • 45