修改域对象会导致错误 - 50% 的时间

Modifying domain objects results in error - 50% of the time

我创建了一个新的 grails 5.1.2 项目,安装了 spring-security(直接安装,而不是通过插件)并安装了 grails-spring-websocket:2.5.0.RC1。

似乎一切正常,直到我开始修改 websocket 控制器中的域对象:

@MessageMapping("/edit")
@SendTo("/topic/result")
protected String edit(String message) {
  Book.withTransaction {
    def book = Book.findByName("Book1")
    book.pages += 1
    book.save(flush: true)
  }
}

这个片段是 Book-controller 的一部分。当我收到错误消息告诉我没有休眠会话时,我添加了 .withTransaction 部分。

现在,结果是随机的。该代码有时有效,有时我收到一条错误消息说

Batch update returned unexpected row count from update [0]

任何帮助将不胜感激:-)

好的,我找错地方了:

我的应用程序为同一域对象获取大量消息。所有这些消息都试图同时更改相同的 属性。

我现在将更改我的数据结构以适应。