10

私は次のことを行います:

def currentUser = springSecurityService.currentUser
currentUser.name = "test"
currentUser.save(flush: true)

// some other code

currentUser.gender = "male"
currentUser.save(flush: true)        // Exception occurs

これは私が得る例外です:

ERROR events.PatchedDefaultFlushEventListener  - Could not synchronize database state with session
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)

このエラーを防ぐにはどうすればよいですか? そのための最善の解決策は何ですか?

私はさまざまなアプローチを見つけました:

  1. ここで、 discard()を使用できます
  2. ここで、 merge()を使用できます

どちらを使用する必要がありますか?

4

1 に答える 1