Tuesday, July 21, 2009

Workaround to a nasty Grails 1.1.1 bug

Hi all

Just wanted to post quickly about a workaround to a Grails bug I dropped into to my application lately. There seems to some strange problem with Grails not binding the GORM methods to the domain objects intermittently.
Eg horrible errors like this

groovy.lang.MissingPropertyException: No such property: save for class: XXXXX

I only seem to get this problem in production on a Tomcat 6.0 server. I super quick fix that seemed to solve it at the time was to restart the tomcat server after a deployment. But that was too shaky for me.

Unfortunately is happening on a really important piece of my application. When i take payment. So i end up taking payment via my provider Paypal but not saving the transaction details in my own database.

Anyway after some searching around it seems like the problem it might have been fixed in the upcoming Grails 1.1.2

But for now this seems to do the trick. Someone posted this quick fix on the forums. The problem is with the hibernate only lazily adding the GORM method and some problem with groovy not recognising them.

So the trick is to get Hibernate plugin to register them at start up. So in your bootstrap.groovy add the following:

class BootStrap {

def grailsApplication

def init = {servletContext ->

switch (grails.util.GrailsUtil.environment) {

case "production":
def clazz = it.clazz
println "Clazz: $clazz count: " + clazz.count();

case "development":
// dev stuff


This simply calls count on all domain objects and prints out the count. You don't have to print out the count it was just nice for me.

Hope this helps


iamsteveholmes said...

Excellent! I ran into the same bug but in my case it only affects child classes of other Domain objects. Has that been your experience as well?

Peter Delahunty said...


Not for me the Domain object that is affected is a top level. But it is a domain object from a plugin. So was wondering if that is the problem.

sbglasius said...

Nice workaround. I have experienced this on the Jetty instance - but only on each third or fourth restart. As I'm nowhere near production yet, I have not given it much attention yet.

But nice to know what can be done.

srinath said...

I am a newbie to Grails and working on GoG since a couple of days.
I got a urgent requirement in Grails on connecting single application with 2 databases.
Installed Datasources Plugin successfully.
but now i was wondering how to configure Datasources.groovy in application.
Could you please explain me in brief the next steps after plugin installation if you used.

Sorry for writing here .


custom essay said...

thanks a lot that fix this bug. I have thought that need always to be against it. GREAT!

Anonymous said...

phone number lookup