I am using Grails and am quite surprised by the way hasMany relationships work. I have a typical hasMany relationship where the parent id is in the child table. When I insert a child and try to save it through the parent object, the parent object's version id gets incremented. My question is: Why should the parent's version id change when there is a change only in the child object?
class Parent { static hasMany = [children: child] } class child { string name Parent parent static belongsTo = [Parent] } def p = Parent.get(1) p.addToChildren(new Child(name: "Roy")) p.save() The version of p gets incremented from 0 to 1. Is there any way I can avoid this in Grails?
Due to the change in version ID of the parent I get a stale object exception. Any help?