Reputation: 3885
I'm trying to upgrade my app to Grails 2.0 and I face following problem. I have a private domain attribute with public getter. I'd like to query this attribute in createCriteria and it returns me: "Could not resolve property ..." exception even if the getter is public. I've seen a Jira bug http://jira.grails.org/browse/GRAILS-8498?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel but it's still not workin. Grails 1.3.7 worked fine.
My code is like: Domain class
class MyClass {
protected boolean reserved = false
protected void setReserved(boolean reserved) {
this.reserved = reserved
}
public boolean getReserved() {
return this.reserved
}
}
Query
def c = MyClass.createCriteria()
def results = c.list {
eq('reserved', true)
}
May be the problem is that 'reserved' attribute name became a reserved keyword in grails because it seems that for other attributes of different names it works...
Upvotes: 1
Views: 984
Reputation: 75671
The problem here is that to enable domain class properties being automatically persistent without having to configure them, fields must be properties, i.e. they have to have a public getter/setter pair of the same type.
Groovy does this for you when you add a public field - it makes the field private and creates a public getter and setter. But if you have a getter or setter already it doesn't do that, and if they're not both public then they're not considered a property (in the JavaBean sense) so the field isn't persistent. So it's more than that the field isn't queryable - it's not even being stored or updated in the database.
Upvotes: 1
Reputation: 77
After a few minutes of examination, I've realized that the problem is in the protected setter. If I set the setter to public, it works. It seems to be a Grails bug, and therefore I've risen grails bug, see:http://jira.grails.org/browse/GRAILS-8637
Upvotes: 0