I am using dynamic scaffolding to create quick out of the box controllers and views to administrate the domain objects (e.g. only visible for admins).
class EventController {
static scaffold = true
}
Whenever I update a domain instance of Event
and then want to view the updated version /event/show/{id}
I get a 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)
This happens in production mode using MySQL database with second level cache turned off.
So here are my questions:
Update
The domain class looks like this:
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')}"
}
}
The behaviour seems to be gone when upgrading to Grails 2.5.1.