views:

289

answers:

1

Assume the following code in a Grails controller:

def action = {
  ClassName o = ClassName.findByFoo(params.foo)
  if (o) {
    o.counter += 1
  }
}

By default Grails uses optimistic locking via the version column added by default to all GORM database tables. However, if a sufficiently large number of multiple concurrent requests are sent to this action the optimistic locking mechanism will break down with the following exception:

org.hibernate.StaleObjectStateException:
  Row was updated or deleted by another transaction (or unsaved-value mapping was 
  incorrect): [ClassName#id]

For domain objects where a failed update/delete is totally non-critical I'd like to disable the locking mechanism, so that no StaleObjectStateException will be thrown thrown. How do I achieve that?

+3  A: 

From mapping DSL docs: you can disable it thusly:

class Person {
  ..
  static mapping = {
      table 'people'
      version false
  }
}

I doubt you can disable it for a specific call.

Jean Barmash