September 16, 2007 1 Comment
Today I finally got to see the two Grails presentations by Jason Rudolph at No Fluff, Just Stuff. It’s not really an exaggeration to say I decided to attend the conference largely because I knew he’d be there. I like the NFJS conferences, but since I’m a one-person company, the “budget” for the conference comes right out of my pocket. I have to really want to go. Not only that, but for the past two years I’ve attended during the March session. It feels like a bit of a luxury to go twice in a given year, especially when many of the presentations in the fall overlap those from the spring.
But Jason was going to be there, and not only is he a real expert, he’s also a big part of the reason I’m involved with Groovy and Grails in the first place. I blogged about it a long time ago, but about a year ago I happened to be teaching a Spring class in Philadelphia. I happened to notice that the local Spring users group was hosting Jason, talking about this Grails thing I’d only heard about.
I guess you could say I was the perfect audience for Jason’s presentation. The fact that I could see all the Rails-like productivity gains and still be able to leverage all my Java experience was worth diamonds to me.
Today, he gave that introductory talk again, and followed up with a more advanced discussion of domain modeling with GORM, Grail’s Object-Relational Mapping framework. The introductory part was a nice refresher, but I was familiar with most of that material.
The advanced talk was very interesting, however. I needed to see how to work with an existing database schema, because that’s real life (despite what the Rails people seem to think). I knew in principle that since Grails just uses Hibernate under the hood, you could just fall back to Hibernate mappings to do whatever you needed. I’d never actually seen that in action, though.
But here was the surprising part. At one point Jason asked the audience if anyone had used the Hibernate Tools project to reverse engineer a database schema. I said I had, and I thought I had, but apparently I really missed the boat on that one.
I’ve tried the reverse engineering process inside an IDE. I originally tried it with MyEclipse, then I tried JBoss IDE. In both cases I felt like the wizard generated as much work for me as just writing the mapping files myself. I never seemed to get the hang of them. I hated seeing Java classes show up that had attributes like “userses” due to some naming convention. Since MyEclipse had content assist on the XML mapping files, it felt easier for me to just write the raw XML.
What Jason showed, however, was an intermediate step that hadn’t occurred to me. He didn’t go from the database schema all the way to the Java classes, which the wizards wanted me to do. Instead he used an Ant build to generate just the Hibernate mapping files and then edited them to suit his domain classes.
“THAT was the equation! Existence! Survival … must … outweigh programming!”
In other words, I get it now.
I tried it with one of my own database schemas this evening, and of course it worked like a charm. I certainly don’t mind editing the resulting XML mapping files, and, even better, I can recommend the practice for clients who have dozens or hundreds of tables.
Thanks, Jason. 🙂 Now I can get back to really learning the framework.