使用Grails动态脚手架时StaleObjectStateException

时间:2014-09-18 07:30:21

标签: mysql grails scaffolding grails-2.4

我正在使用动态脚手架来创建快速开箱即用的控制器和视图来管理域对象(例如,仅对管理员可见)。

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')}"
    }
}

1 个答案:

答案 0 :(得分:0)

升级到Grails 2.5.1时,行为似乎消失了。