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":
grailsApplication.domainClasses.each{
def clazz = it.clazz
println "Clazz: $clazz count: " + clazz.count();
}
break;

case "development":
// dev stuff
break;
}
}

}


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

Tuesday, July 7, 2009

Grails developer available: Get them while there hot

Hi Peeps

This is just quick shout out to the community. I will be available to start a Grails contract from 20th July. So if you have any new cool projects coming up and are looking for a developer then let me know.

You can get me on peter.delahunty@gmail.com