Grokking GORM - Part 1: Conventional Thinking
Posted by Jason Rudolph on July 20th, 2007
For any developer that’s ever touched JDBC (and it’s safe to assume that’s most Java devs, right?), GORM is one of the many Grails features that addresses a clear and prominent pain point in the Java space. Put simply, GORM is humane ORM. It means leaving the low-level database-related plumbing to the framework and instead investing your time in the business tier. After all, your app needs to solve a business problem, right? And it’s a pretty safe bet that your business analysts didn’t spend time listing out any requirements about managing DB connections, result sets, sessions, or DAO code. Nope. They’re focused on a much higher level, and we should be too.
If you’re fortunate enough to be developing a greenfield application, you can just follow the Grails conventions and come close to forgetting that there’s a database under the covers at all. GORM dynamically equips you with all the persistence methods you need to manage your domain, and yet you still have the ability to drop down to that lower level should the need arise.
NFJS is in RTP this weekend, and in “Advanced Domain Models in Grails”, I’ll be looking first at the functionality that GORM provides out-of-the-box and then exploring how you can mold GORM to take advantage of its benefits in a variety of environments. We’ll start by looking at a sample app that colors within the lines of the Grails conventions, and you can download and try out that app now. (Be sure to have a look at the included README files for all the details.)
Inside the app you’ll find working examples of various relationship types (including many-to-many, which people occasionally struggle with at first), constraints, and the always-cool dynamic finders. Check out the test cases in test/integration. Among other things, the test cases illustrate exactly how the entities relate to one another. (Want to know which side of a many-to-many relationship can perform a cascading save operation? Check out the tests.) To run the tests, just execute grails test-app from the command line.
Of course, there’s just no substitute for hands-on experimentation. To interact with the domain models yourself, simply navigate into the project directory and run grails console to get an interactive shell where you can
experiment with the domain objects first-hand. Or better yet, write additional tests of your own! If you get adventurous (and I hope you do), try out some of the many other possibilities available in GORM.
Be sure to watch for Part 2, where we begin our venture into the land of non-conformity. Stay tuned.



August 26th, 2007 at 12:05 pm
I would love to get started with Grails, but alas… I can’t.
This is just another example of a bunch of problems. grails says “I cannot do that… because… nightly build shot blah blah please use other version or run grails upgrade”.
So I ran grails upgrade.
I am getting a 503 error.
Grails is changing too much all the time, it seems to be impossible to “start”. I mean - I do not want to start with grails 0.5.6 because 0.6 seems so much more sophisticated and 0.5 will soon cease to exist.
I would surely be willing to buy a book, if need be. Why not. But I fear a book will not help me either, because a book that is several months old (or at even a few weeks only) will most certainly refer to an outdated grails version.
August 27th, 2007 at 8:52 pm
Hi Rupert, I'm sorry to hear about your frustrations with Grails. I wonder if you can help us track down your issues.
This is the first I've heard of this issue. If you can describe your environment and the steps needed to reproduce this issue, we'd like to help. The Grails JIRA site is open for anyone to log issues. In fact, we encourage it.
Such is the face of technology, but the Grails roadmap is clear in its intention to continue to grow the framework. Like most projects, you can expect to see a fair amount of change (albeit all in the name of progress) on the road to 1.0. Of course, once we reach 1.0 later this year, future changes will have a greater consciousness toward backward compatibility with older versions.
Books aren't for everyone, but luckily there are many other sources to help you learn about Grails.
I do hope you'll help us track down your issue and give Grails another shot.