Fork me on GitHub

28 Apr 2009

Grails Upgrade

We've just finished upgrading our sites to Grails 1.1 and I thought it would be worth sharing some of the fun we had with the process.

First and foremost was a call site caching bug in Groovy 1.6.0 that caused chaos with our unit and integration tests. Basically any time we mocked a class then demanded behaviour on a static method or any time we used the metaClass to override a static method (among other things that's pretty much any unit test that goes anywhere near a domain class) the behaviour wouldn't get torn down again. This caused symptoms such as stubbed dynamic finders leaking from unit tests and breaking integration tests that would pass when re-run in isolation. We got as far as refactoring a whole bunch of test code that mocked static methods before Burt Beckwith pointed out to me that simply replacing $GRAILS_HOME/lib/groovy-all-1.6.0.jar with the newer version from the Groovy 1.6.1 or 1.6.2 release would fix the problem.

Unfortunately the same bug has another effect that was quite catastrophic for us. Any Hibernate proxy of an instance of a domain class involved in an inheritance hierarchy will throw ClassCastException when you try to access a subclass property or do an instanceof check. I blogged already about the instanceof issue but it's actually wider ranging than I realised at the time. It can cause very unpredictable behaviour because complex relationships between objects and the way they are loaded by a controller before a page is rendered can cause this error to pop up under obscure conditions that are very hard to nail down with test coverage. To solve the problem we've had to use eager fetching in places where associations are typed as the base class of an inheritance hierarchy and to use explicit checks for proxies such as:

if (o instanceof HibernateProxy) {
o = GrailsHibernateUtil.unwrapProxy(o)

Hopefully this bug will be fixed in Grails 1.1.1 and we will be able to use the default lazy loading behaviour in all relationships.

Other problems we encountered included:

  • The onLoad Hibernate event handler on domain classes now seems to run at a slightly different time in the object life cycle: before any eager fetched collections are loaded. We had one domain class that was doing some initialisation (calculating the percentage of votes each answer to a poll had received and storing it in a transient property) that no longer worked as the persistent collection it was trying to iterate over was always empty. This was simple to refactor out and in fairness was pretty horrible anyway.

  • Config.groovy and related external config files are no longer loaded when running unit tests so any unit test that excercises code doing ConfigurationHolder.config.some.value.or.other blew up. We solved this by simply adding the following to _Events.groovy to load up config prior to the unit tests running:
    eventTestPhaseStart = { phase ->
    if (phase == 'unit') {
    ConfigSlurper slurper = new ConfigSlurper(GrailsUtil.environment)
    def configClass = getClass().classLoader.loadClass("Config")
    def config = slurper.parse(configClass)
    ConfigurationHelper.initConfig config // this step loads the external environment config file(s)
    ConfigurationHolder.config = config

  • Logger configuration has completely changed (for the better) in Grails 1.1

  • Some of our tests were explicitly setting the level of particular loggers to 'OFF' because the test is deliberately causing an error condition and we didn't want the console polluted with a huge stack trace. This no longer works as the logging abstraction has changed to SLF4J which does not allow you to directly set the level on its Logger class. Having better things to do than unwrapping logging abstractions I just turned logging off altogether in the test Grails environment.
    log4j = {
    root {

  • It looks like binding errors don't get reported on nullable properties when using = params in a controller. I've raised a bug.

  • There's been a minor change to the <g:select> tag. Previously the disabled attribute followed the HTML convention (disabled="disabled") but now the attribute value needs to be a boolean. I guess this actually makes more sense than the goofy HTML convention but I really expect most of the attributes on those sorts of tags to be pure pass-through.

  • The mockDomain method used by unit tests seems to be a little inconsistent when dealing with inheritance heirarchies. If you do mockDomain(BaseClass) then try to use subClassInstance.subClassProperty it fails with a MissingPropertyException. I've raised a bug.

  • We had customised Package.groovy to deploy our app at the root context. It seems this is now directly supported as an option in Grails 1.1 by setting = '/' in Config.groovy. I think this option was already available in Grails 1.0.3 but our patch pre-dated us upgrading to 1.0.3. One of the things I was trying to achieve while upgrading was to ensure we were patching Grails and any plugins as little as possible.

  • I'd upgraded our selenium plugin (not the one in the Grails plugin repository) a while back to cope with Grails 1.1 and upgraded the selenium server it contained at the same time. It turns out the new selenium server will time out attempting to click any anchor that uses the javascript: protocol in its href. Luckily this was only being done in 2 places in our app and was easily fixed by using href="#" instead.

One other thing we decided to do was to replace our existing suite of webtests with functional tests. Webtest has never been popular with the developers on our team and we had made a number of modifications to version 0.4 of the plugin in order to support issues like config loading and running the app at the context root of the server. These modifications caused some headaches when trying to upgrade the plugin so we decided to drop it and port the tests over to the functional test plugin. Generally I'd still rather be writing Selenium tests than using either webtest or functional tests but the functional test syntax is a little nicer and less "pseudo-XML" than webtest's.


Fraaargh said...

Whaou, that is NOT what you would call a trivial upgrade :/ Thanks for all the explanations, it may help.

Daniel K said...

It is things like that which make me think about leaving my current project the way it is (1.0.3) and migrate it to a regular Spring MVC, Hibernate, Maven, GWT app some time in the future. I am so sick of this tiny little issues ALL OVER THE PLACE.

I just dont want to deal with this buggy stuff anymore. Using Grails feels like walking on eggs, you have to be careful all the time (did I use x uncorrectly or is it a bug? did others encounter the same issue -> check mailing list? Is there a bug already-> check JIRA) all the time for stuff that should just work.

Graeme Rocher said...

All I can say is sorry for all the difficulties you had in upgrading. Grails 1.1.1 (out next week) addresses most of the hassles you have had including those related to proxies, the static method Groovy bug, and the unit testing hierarchy issues.

Rob said...

Well, it has been difficult but in my perverse way I actually enjoyed it and learned a lot! I think the upgrade will prove to be worth the effort. For a start we're already seeing an improvement in page response time, which I'm guessing is due to the enhancements to GSP rendering. There is also a small mountain of tech debt around things like form binding, failed save handling, locking, enum persistence, etc. that Grails 1.1 gives us the tools to tackle. I'm looking forward to getting stuck into some of that stuff now that the app is up and running on 1.1.

We'll upgrade to 1.1.1 as soon as it's out barring any blocking issues. I expect that will be a vastly simpler process.

I can sympathise with Daniel K's comments but I'd honestly still rather be using Grails than any other platform. As I see it we've been bitten by; 1) adopting Grails early hence having code written against Grails 0.6 at the core of our app, 2) having a massive application so the sheer weight of code is a problem unto itself and 3) by the fact we have an inheritance hierarchy at the core of our domain which unluckily was the thing that caused us the most pain.

Rob said...

Oh boy here we go again. I just tried Grails 1.1.1 - 110/531 unit tests fail. That's just unit tests, I haven't even tried running integration tests.

marry said...

Blogs are so informative where we get lots of information on any topic. Nice job keep it up!!

Consumer Behaviour Dissertation

michaelvk said...
This comment has been removed by the author.
Dissertation Writing service said...

This post was very useful to me it contains all information that was needed to Clarify all confusions regarding the subject. I express my appreciation to you for this post.

Dissertation writing advice

zcocorporation said...
This comment has been removed by the author.
Admin said...
This comment has been removed by the author.
Admin said...
This comment has been removed by the author.
Admin said...

Excellent is the only word i can give u for this wonderful blog, keep it up. I will come back again to read some more interesting things on this topic. Facebook Timeline Cover Page Designs

Fabian Smith said...
This comment has been removed by the author.
Dheeraj said...

I recently came across your blog and have been reading along.I'm impressed. You're truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. I'm saving this for future use.The Seo Portal

SEO said...

Now I am really thinking what's best for it. Thanks a lot for all the help. It will be just so fine.
Indian wedding footwear

faye smith said...

Nice post. Great blog. Thanks for sharing. It was very interesting and meaningful. Cheap Essay Writing

faye smith said...

Such a nice post. Keep it up. Sell Gold Coins

faye smith said...

This is really a great blog post.Thanks for sharing information good job keep it up. Beauty Reviews

faye smith said...

I really enjoy your blog, keep up that good job! Good luck, smile SEO Company

Felix Smith said...

Excellent site, keep up the good work my colleagues would love this. Hire a Desktop App Developer

Felix Smith said...

This site is excellent and so is how the subject matter was explained. I also like some of the comments too.Waiting for next post. Cheap Essay Writing

Felix Smith said...

Thanks for the nice information. I am sure, I will stumble this to my stumbleupon account. This will assist a lot of users. Cheap Essay Writing

Felix Smith said...

Thank you for taking the time and sharing this information with us. It was indeed very helpful and insightful while being straight forward and to the point. Hire a PHP Developer

Felix Smith said...

I read your whole blog. Your work is really good and inseparable .Thanks for sharing. iPhone App Marketing

Narayan said...
This comment has been removed by the author.
College Ppaper said...

Comment deleted
This comment has been removed by the author.

cheap Cheap Essay Writers online

Felix Smith said...

Thank you for sharing these ideas. It amazes me how you manage to choose your favorites. Good luck to the next post. Hire PHP Developers

Felix Smith said...

Howdy, I actually love reading through your posts, thank you for the truly great post. Paper Writing Services

Felix Smith said...

Well this is really a informative post and I am glad to read such a great post. I came to your site by mistake but from now I am going to read all of your posts. SEO Packages

Syed Faizan said...

his blog Is very informative, I am really pleased to post my comment on this blog. It helped me with ocean of knowledge so I really believe you will do much better in the future. Good job web master. Free Calls

Felix Smith said...

The post is interesting. I really never thought I could have a good read by this time until I found out this site.Thanks!
Wholesale Towels

Felix Smith said...

I'm so enjoyable when reading your post. Thank you for sharing. Used Police Cars

Felix Smith said...

A very good and informative article indeed . It helps me a lot to enhance my knowledge, I really like the way the writer presented his views. Debt Collector

Felix Smith said...

I appreciate the write and the real insight of the writer on the subject. well done
Debt Collection

Felix Smith said...

Great Blog!! That was amazing. Your thought processing is wonderful. The way you tell the thing is awesome. You are really a master. Debt Collector

Felix Smith said...

Excellent is the only word I can give you for this wonderful blog, keep it up. I will come back again to read some more interesting things on this topic. Debt Collection

Felix Smith said...

I think that this blog is really cool .so please visit my this site and get collection information. Debt Collection

saranya zinavo said...

I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.
website designing company

Mia Smith said...
This comment has been removed by the author.
Mia Smith said...
This comment has been removed by the author.
Evince said...

This is the Good information you are Sharing:)

Outsource Web Development India

Mia Smith said...

I really like this website. This is a great resources, provide you with your free distribution. It gives in depth information. Thank you for this valuable information. Macy's Coupon
JcPenney Coupons
Bluefly Coupon Codes
Target Promo Codes
Barnes & Noble Coupon Code
Groupon Promo Codes
Amazon Promo Codes
Best Buy Coupons
American Eagle Promo Code
AutoZone Coupons
Walmart Coupon Codes
Next Day Flyers Coupon Codes
Overstock Promo Codes
bebe Coupon Codes
Light In The Box Coupons
SmartBargains Coupons
Bed Bath and Beyond Coupon

lelle sandy said...

thats awsam thanks for sharing.Geo Essay

Tom Brian said...

Well, my huge data set (Biology; EEB) and resulting dissertation tell a compelling story. Guess I was lucky...
Airport Taxi

Hamza Shahzad Shahzad said...

Nice information, i hope you keep writing.
Search Strings
SEO Company
Google Adwords
Social Media
Web Analytics
Conversion Optimization
Reputation Management

sophia martin said...

Cheap Essays
Wow Amazing post really informative thanks for the great post.

sophia martin said...

Cheap Essays
Wow Amazing post really informative thanks for the great post.

Tina brian said...

Awesome post this one realy helped me at my point of confusion :) Realy thanx alot for sharing :) Keep it up ;)
Billy Bishop Airport
YTZ Airport
Taxi to Billy Bishop Airport

zachray taylor said...

Wow amazing stuff I really enjoyed thanks for the amazing stuff.
Cheap Essays

Tina brian said...

thanx for sharing nice info :)
Cheap Essay

Tina brian said...

thats the post i've been seeking for. Nice info thanx for sharing keep it up ;)
Cheap Essay

Tina brian said...

Nice post thanx for sharing such usefull info it realy helped me !! :)
Toronto Pearson Airport Taxi
Toronto Airport Taxi
Pearson Airport Taxi

Tina brian said...

Thanx for sharing such useful post keep it up :)

Fabian Smith said...

There are some very good sources here, thanks for being so kind to post here. Hamilton Resourcing
Human Resource Solutions UAE
Psychometrics Tests
Psychometrics Test Dubai
Talent Management
Integrity International
Executive Recruitment UAE
The McQuaig Psychometric System
The McQuaig Job Survey
The McQuaig Word Survey
The McQuaig Self-Development Survey
Executive Search Firms in Dubai
Head Hunters Dubai
Executive Recruitment in Dubai
Emirati Talent Management
Executive Headhunters Dubai
Executive Recruitment Dubai
Executive Search Dubai

David Peter said...

I Like Ur Post thanks for the shareing with Us.Find Assignment Writing Help

Metamorfosis said...

Pelatihan SDM is a network marketing and training information or training an employee who has worked with many consulting firms and training institutions.
pendidikan dan pelatihan sdm, pelatihan akuntansi, sales marketing, manajemen bisnis, administrasi kantor, lembaga training motivasi, pelatihan sumber daya manusia, training manajemen, training sdm, informasi training, pusat pelatihan, pelatihan rumah sakit, training provider jakarta, training jakarta, training consultant jakarta, training center,

Julia Smith said...

I don't know what to say except that I have enjoyed reading. Nice blog.I will keep visiting this blog very often. Research Paper Writing Services
Thesis Writing Services
Admission Essay Writing Services
Assignment Writing Services
Book Report Writing Services
Power Point Presentation Services
Paper Writing Service
Letter Writing Services
Editing Services
Proof Reading Services
Proposal Writing Services

Dr. Zaki Anwar, M.D said...

Great info! I recently came across your blog and have been reading along. I thought I would leave my first comment.
Workers Compensation
Pain Treatments
Botox Injections
Epidural Injections
Epidural Lysis Procedure
Facet Blocks
Intercostal Nerve Blocks
Intrathecal Pump Therapy
Intradiscal Electrothermal Therapy
Intercostal Nerve Blocks
Joint Injections
Platelet Rich Plasma
Percutaneous Discectomy
Racz Epidural Neurolysis
Radiofrequency Lesioning
Selective Nerve Root Blocks
Spinal Cord Stimulation
Sympathetic Nerve Blocks
Pain Locations
Arm Pain
Abdominal Pain
Back Pain
Cancer Pain
Chest Wall Pain
Disc Herniation

Maya Angelou said...

excellent post
Hijama Therapy Training Courses
Hijama Therapy London
Prophetic Medicine Course
Wet Cupping Therapy Course
Diploma in Hijama Therapy

Maya Angelou said...

Amazing post
Storage services dubai
Furniture Installation In Dubai
Moving and Storage
Movers And Packers
International relocation companies in Dubai
Mover companies in dubai

Jessica Amy said...

Great Post!
Niagara Falls Airport Taxi
Richmond Hill Airport Taxi
Markham Airport Taxi
Vaughan Airport Taxi
Pickering Airport Taxi

rehan said...

The info you provided in the blog that was really unique I love it!!!
Dermstore Coupon Code
6pm Coupon Code
Walgreens Coupon Code

Jacky said...

Wow.. Awesome This is Great.. Wonderful information.. I am impressing Thanks..

Ecommerce Web Development Company

App Planit said...

I'm so amazed together with you that will make your blog like this to be really great so we truly wanted to have a nice and interesting blogs such as this. Cheap Essays

Curtis Albert said...

It is great of you to share with us the fun you had when you were upgrading your site to Grails 1.1. This is incredible and indeed you had a lot of fun. Thanks a lot for sharing.
Letter of Reference Writing Help

حسام داود said...

level تسليك مجارى بالرياض
افضل شركة تنظيف بالرياض
تنظيف شقق بالرياض
تنظيف منازل بالرياض
شركة غسيل خزنات بالرياض
افضل شركة مكافحة حشرات بالرياض
رش مبيدات بالرياض
شركة تخزين عفش بالرياض
تنظيف مجالس بالرياض
تنظيف فلل بالرياض

Shaista Lodhi said...

I am glad to see that people are actually writing about this issue in such a smart way, showing us all different sides to it. Thanks for sharing, please keep it up.

Also checkout our happy new year 2017 Wishes new collections.

Rabya Atif said...

I read blog thoroughly,its quite informative and well written covered the topic very well.Thanks for sharing.
Also checkout Pakistani chat rooms

Nida Tareen said...

I recently came across your blog. It’s quite interesting and nice blog .You’re truly well informed. Thanks for sharing.
Also checkout Game Killer APK Free Download

ailsa marshall said...

Nice post.Great blog.Thanks for sharing. It was very interesting and meaningful.
Also checkout Surgical instruments

ailsa marshall said...

Very informative and well written post! Quite interesting and nice topic chosen for the post.
Also checkout Surgical Instrument

ailsa marshall said...

I read your whole blog. Your work is really good and inseparable .Thanks for sharing.
Also checkout Security services Melbourne

Tristar Traders said...

Ultimate article post in this blog.Thanks for sharing these useful information.
Gone are the days when a business laid down an annual sum to have its information listed in the Yellow Pages. These days it’s crucial for all businesses to instead prominently list themselves in online directories.AIR pros is a directory of service companies in your area with a geolocation system, automatic translation of the content.The site is optimized to facilitate the referencing of referenced companies.You can search for companies by department or city and look at their profile before contacting them.

Yasin Bawani said...

I love reading through your blog. It’s very interesting blog. Thanks for sharing valuable information to us.

Unknown said...

I have gone through the post and I must admit that I like it. Keep doing the great work. I will definitely have to bookmark this page for future reference. I will also refer my friends to come and have the same experience as I did. Thanks so much. Anyone looking for Research papers help check out our Sample Essays and the assignments we have done before

Rabya Atif said...

I really enjoyed reading this post, big fan. Thanks for sharing valuable information to us. Keep up the good work W88asia

لمار للتسويق الالكتروني said...

شركة تنظيف بنجران
شركة تنظيف المنازل بنجران
شركة نظافة عامة بنجران
أفضل شركة تنظيف فلل بنجران
شركة نظافة الأسطح بنجران
شركات النظافة  بنجران
شركة نظافة عامة بنجران
أرخص شركة تنظيف شقق بنجران
شركة تنظيف منازل بنجران
شركة تنظيف فلل وقصور بنجران
شركة تنظيف اثاث و مجالس بنجران
شركة تنظيف سجاد و موكيت بنجران

لمار للتسويق الالكتروني said...

شركة تنظيف خزانات بدبى
شركة تنظيف بالبخار بدبى
شركة عزل خزانات بدبى
شركة تنظيف بدبى
شركة مكافحة حشرات بدبى
شركة تنظيف خزانات بالشارقة
شركة تنظيف كنب بالشارقة
شركة تنظيف في الشارقة
شركة مكافحة الحشرات بالشارقة