【发布时间】:2015-08-11 16:40:15
【问题描述】:
我正在使用动态脚手架来创建开箱即用的快速控制器和视图来管理域对象(例如,仅对管理员可见)。
class EventController {
static scaffold = true
}
每当我更新Event 的域实例然后想查看更新的版本/event/show/{id} 时,我都会得到StaleObjectStateException
2014-09-18 08:51:26,274 [http-bio-127.0.0.1-50000-exec-8] ERROR org.codehaus.groovy.grails.web.errors.GrailsExceptionResolver - StaleObjectStateException occurred when processing request: [PUT] /event/update/15
Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [ch.silviowangler.zscsupporter.Event#15]. Stacktrace follows:
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [ch.silviowangler.zscsupporter.Event#15]
at ch.silviowangler.zscsupporter.EventController.$tt__update(script1410592579337609530153.groovy:65)
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:189)
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
at grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.doFilter(GrailsAnonymousAuthenticationFilter.java:53)
at grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter.doFilter(RequestHolderAuthenticationFilter.java:49)
at grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter.doFilter(MutableLogoutFilter.java:82)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
这发生在使用 MySQL 数据库并关闭二级缓存的生产模式中。
所以这是我的问题:
- 由于我使用动态脚手架,我无法在运行时分析脚手架代码,对吧?
- 谁能告诉我从哪里开始分析甚至解决这个问题?
更新
域类如下所示:
class Event {
Date startDate
Date endDate
String title
String location
String organizer
String externalLink
static constraints = {
title maxSize: 100, nullable: false
startDate nullable: false, attributes: [precision: 'minute']
endDate nullable: true, attributes: [precision: 'minute']
location nullable: false, maxSize: 50
organizer nullable: false, maxSize: 30
externalLink nullable: true, maxSize: 255, url: true
}
@Override
public String toString() {
return "Event:{id:${id}, title: ${title}, startDate: ${startDate?.format('dd.MM.yyyy HH:mm')}, endDate:${endDate?.format('dd.MM.yyyy HH:mm')}"
}
}
【问题讨论】:
-
您的域是否有版本?您是否将版本属性与更新一起发送?
-
是的,它是版本化的。我希望脚手架代码将版本属性与相应的更新一起发送。还是不能开箱即用?
-
开箱即用。使用您的示例域和纯脚手架控制器,我无法使用 Grails 2.4.2 重现相同的错误。
-
只能在生产模式下重现。部署为 WAR 的含义
-
你能在本地使用 run-war 重现它吗?
标签: mysql grails scaffolding grails-2.4