I have the following setup:
class Parent {
static hasMany = [ children: String ]
}
class ParentController {
def create() {
Parent entry = params.id ? Parent.load(params.id as long) : new Parent()
entry.properties = params
if (request.method == "POST") {
if (entry.validate()) {
entry.save()
assert !entry.hasErrors()
println entry.children // prints [two, one]
println Parent.load(entry.id).children // prints []
redirect(action:'index')
return
}
}
return [
entry: entry,
entities: ["one","two"]
]
}
}
Why are the children not saving along with the parent?
(I also tried making the children another domain object, however that made no difference)
Although I'm not sure exactly what solved my problem, changing the save()
to save(flush: true)
allowed me to see the exception that Hibernate was throwing.