Grails StaleObjectStateException in lock () method

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) // The exception is launched here

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), . , ?

.

+4
1

100% StaleStateException/OptimisticLocking:

  • . , ,
  • @Transactional . , . . ( ) . , , , 100% .
  • , - . . , , , .
  • , belongsTo/hasMany, , - . , , . , : https://www.youtube.com/watch?v=-nofscHeEuU. , , , , .
  • , , , , , . , orderService.update(order), , , , orderService.setStatus('foo', orderId), . StaleState, . , , , .
0

All Articles