I get a StaleObjectStateException exception while I try to lock a domain object inside a transactional service (grails 2.3.8):
@Transactional
class AnalyticsService {
boolean newStreamView(Long streamId) {
Stream stream = Stream.lock(streamId)
Of course, this only happens if there are many simultaneous calls to this service. As I can see, hibernation is trying to block the ID and version parameters:
select id from stream where id =442 and version =305 for update
and it fails. If I disable optimistic locking (version: false) inside this domain class, everything works fine (sleep mode just uses an identifier to lock the string).
As stated on the Marc Palmer Blog , it seems that:
StaleObjectException () , - GORM Domain.lock(id). "",
, .
StaleObjectStateException ON?
(: false), . , ?
.