I'm using grails 2.4.2 and have in my controller-update method the following code:
@Transactional
def update(ErtIncommingInvoice ertIncommingInvoiceInstance) {
if (ertIncommingInvoiceInstance == null) {
notFound()
return
}
// Concurrent-Update Test
if (ertIncommingInvoiceInstance.version != params.version as int) {
flash.warning = "Another user changed the record! (Concurrent Update Error)"
ertIncommingInvoiceInstance.errors.rejectValue("ertInfo", "concurrent.update.error")
respond ertIncommingInvoiceInstance.errors, view:'edit'
return
}
even in the case, the error is detected and the errors-object is set and the method-flow does not execute the
ertIncommingInvoiceInstance.save flush:true, failOnError: true
the data is already changed in the database. The edit-view is shown, but doesn't display the error, only the flash-message.
Where's my error in reasoning?
Grails will call validate
before any save
and overwrite whatever you set in the errors
object. Additionally, Grails will call save
automatically on your objects after your method finishes. You should either call discard()
on any objects you've changed but don't wish to persist or create a transaction using a withTransaction
block and manually roll it back.