You'll have to provide a little more information about what is going on. Is this error occurring every time you save a user, or only when you call saveUser(user)
at the same time from multiple threads? Or is it happening anytime you call findUserById()
or saveUser()
?
You might want to look into the Isolation parameter for the @Transactional
annotation. The default is Isolation.DEFAULT
(which is the "...default isolation level of the underlying datastore").
The way you are using this function should determine what value you want to supply for this argument. Will your saveUser(user)
function almost always conflict with with another call to that function? Then you might want to use:
@Transactional(isolation = Isolation.READ_COMMITTED)
Edit: I will say it does sound like this is functioning properly, though. It makes sense that if your object is modified in another thread, and then you try to commit that same object from another thread at the same time, you'd get StaleObjectStateException