I have a grails domain object that I validate and then save as such:
if(foo.hasErrors()) {
transactionStatus.setRollbackOnly()
respond foo.errors, view: 'create'
return
}
foo.save flush:true, failOnError:true
println(foo)
There are no errors given on the save. But when I call the println, it says my object is unsaved. However, if I check the database, it has indeed been persisted. Is there something I can check to tell me why grails is telling me it is unsaved. The grails version is 3.0.9.
After more testing, it looks like it is related to the way I specify the key in my domain mapping.
static mapping = {
version false
autoTimestamp false
id name:'foo_id', generator:'increment'
}
If I remove the id field and let Grails handle it by default the object is saved properly. If I add the id field back, it has the issue described above. Is there a reason for it?