Friday, December 26, 2008

Grails - findAll ( " from Book as .. " ) not working

Maybe I'm dumb.. but this stumped me for a couple of hours.
In Grails 1.0.3, code similar to example in http://grails.org/doc/1.0.x/ref/Domain%20Classes/findAll.html wasn't working.
i.e, queries similar to the example Book.findAll("from Book as b where b.author=?",['Dan Brown']) weren't working.

Initially, I thought maybe we need to use the actual table name.

Finally figured out that you need to use the full java package path of the domain class.
i.e, it needs to be Book.findAll("from com.packagename....Book as b where b.author=?",['Dan Brown'])

Wish the documentation was kind enough to mention that tidbit.
There's an entry in the Grails issue tracker too:
http://jira.codehaus.org/browse/GRAILS-3023