hibernate - 禁用非关键Grails/GORM域类的锁定

标签 hibernate grails gorm

在Grails Controller 中假定以下代码:

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

默认情况下,Grails通过默认添加到所有GORM数据库表中的version列使用乐观锁定。但是,如果将足够多的多个并发请求发送到此操作,则乐观锁定机制将崩溃,但以下情况除外:
org.hibernate.StaleObjectStateException:
  Row was updated or deleted by another transaction (or unsaved-value mapping was 
  incorrect): [ClassName#id]

对于失败/失败完全不重要的域对象,我想禁用锁定机制,这样就不会抛出StaleObjectStateException异常。我该如何实现?

最佳答案

mapping DSL docs:您可以这样禁用它:

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

我怀疑您可以针对特定的 call 禁用它。

关于hibernate - 禁用非关键Grails/GORM域类的锁定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1750894/

相关文章:

hibernate - Spring:尚未配置事务管理器

java - Hibernate - 不使用 import.sql 的种子数据库

java - 将 Grails 应用程序从 2.2 升级到 2.4 时出错

mysql - g :select using two combobox in grails

java - Hibernate保存和SQL插入有什么区别?

java - Spring @Value 字段为空

grails - Grails从许多方面拉物体

grails - grails 3.2.6无法初始化测试数据 “is not a domain class or GORM has not been initialized correctly”

Grails/GORM : difference between lazy: false & fetchMode eager

hibernate - Grails条件:id不在hasMany列表中