Skip to main content
Edited title to be more descriptive
Source Link
Rob Hruska
  • 120.8k
  • 32
  • 170
  • 193

one-to-many grails problem Grails hasMany: when child is updated, parent's version changes

I am using grailsGrails and i am quite surprised by the way has manyhasMany relationships work. I have a typical has manyhasMany relationship where the parent id is in the child table. When iI insert a child and try to save it through the parent object..The, the parent objectsobject's version id gets incremented. My question is why: 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() 

theThe version of pp gets incremented from 0 to 1. Is there any way iI can avoid this in grailsGrails? Due

Due to the change in version ID of the parent iI get a stale object exception. Any help?

one-to-many grails problem

I am using grails and i am quite surprised by the way has many relationships work. I have a typical has many 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 objects 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?

Grails hasMany: when child is updated, parent's version changes

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?

edited tags
Link
Bozho
  • 599k
  • 147
  • 1.1k
  • 1.2k
Source Link
prabha
  • 41
  • 1
  • 2

one-to-many grails problem

I am using grails and i am quite surprised by the way has many relationships work. I have a typical has many 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 objects 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?