Overriding setter on domain class in grails 1.1.2

Posted by Pavel P on Stack Overflow See other posts from Stack Overflow or by Pavel P
Published on 2010-02-06T18:52:02Z Indexed on 2010/05/31 4:32 UTC
Read the original article Hit count: 236

Filed under:
|
|
|
|

I have following two domain classes in Grails 1.1.2:

class A implements Serializable {
 MyEnumType myField
 Date fieldChanged

 void setMyField(MyEnumType val) {
  if (myField != null && myField != val) {
   myField = val
   fieldChanged = new Date()
  }
 }
}

class B extends A {
 List children
 void setMyField(MyEnumType val) {
  if (myField != null && myField != val) {
   myField = val
   fieldChanged = new Date()
   children.each { child -> child.myField = val }
 }
}

When I set B instance's myField, I get the setter into the cycle... myField = val line calls setter again instead of assiging the new value.

Any hint how to override the setter correctly? Thanks

© Stack Overflow or respective owner

Related posts about grails

Related posts about domain