Monday, October 10, 2011

Grails (hibernate) "Could not find a setter for property in class"

When working on a Domain class (in grails) I wanted to add a convenience method to return some information.

e.g. I had a property endDate, and I wanted to have a method isActive to return true if the endDate does not exist or is in the future.

boolean isActive(){
if(endDate==null) return true;
return endDate
}


However when I try to run the app I get

Solution is

def isActive(){
if(endDate==null) return true;
return endDate
}


If defined as boolean (or int string etc), then Hibernate interprets it as a getter, and will look for corresponding setter, and throw an exception when not finding it.
Defined as with a def, means this won't happen.
Alternative is to set it in the transients static.

e.g.
static transients = [ "active" ]
http://grails.1312388.n4.nabble.com/Transient-properties-td1345135.html

No comments: