File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Working with legacy database - a challenge in Groovy

 
Vyas Sanzgiri
Ranch Hand
Posts: 686
Chrome Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the most important topics in Groovy and Grails is
"Managing legacy tables for 1:M, M:M relationship and using composite keys (without using separate id field or manipulating Hibernate mapping files)"

We had to struggle with legacy database and Grails and finally came up with some kind of crude solution. This requires a lot of manual intervention and I definitely would not call it a simple CRUD as other Groovy-Grails application. Are there any good pointers to the topic of legacy database?
 
Vyas Sanzgiri
Ranch Hand
Posts: 686
Chrome Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are there any examples of this approach in the Grails 1.0 Web Application Development book?
 
Matthew Taylor
Rancher
Posts: 110
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The January and February issues of GroovyMag have articles on the "Legacy database from Hell". There is also a lot of information about this in Grails in Action. I've been very successful doing this type of thing in the past using static mappings.
 
Vyas Sanzgiri
Ranch Hand
Posts: 686
Chrome Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please share some code? Do you have any examples in your blog?

I do not subscribe to those magazines but I tried other Groovy books including Grails in Action and I am still struggling. Is there a new edition of the book?
 
Matthew Taylor
Rancher
Posts: 110
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Googling "grails legacy database" gave me this very informative article on the first page of results.
 
Jon Dickinson
Author
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vyas,

The Grails Web Application Development book does not cover working with legacy databases.

Thanks,
Jon.
 
Vyas Sanzgiri
Ranch Hand
Posts: 686
Chrome Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like there are more resources available than what I started out 6 months back. I will check out the links

Thanks!
 
Vyas Sanzgiri
Ranch Hand
Posts: 686
Chrome Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Checking this out in the context of Groovy in Action book and the latest version 1.1. We are really struggling to apply groovy and grails out of the box to legacy db. We are researching and doing more work than prob Java. Feel that there is no ROI
 
Peter Ledbrook
author
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your mileage will vary depending on how far your database deviates from the Hibernate norm. The Grails user mailing list a useful resource for answering specific database mapping questions. As for ROI, there is a one-off hit in advance associated with the legacy mapping, but you gain the advantage of the dynamic finders, transactional services, GSPs, and other benefits.

On the legacy mapping front, I don't think the GORM mapping DSL supports every feature of Hibernate, so you may have to map some of your classes using Hibernate XML mapping files. It's not pleasant, but at least you only have to do it once.

Cheers,

Peter
 
chris webster
Bartender
Pie
Posts: 2359
31
Linux Oracle Postgres Database Python Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"The Definitive Guide to Grails" (2nd edition) by Graeme Rocher and Jeff Brown has a whole chapter on integrating legacy databases and Grails using Hibernate (re-mapping keys and relationships etc).
 
Peter Ledbrook
author
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to avoid confusion, Grails in Action also has a chapter on legacy database integration

Peter
 
Vyas Sanzgiri
Ranch Hand
Posts: 686
Chrome Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The last 2 posts by Peter and Chris have been awesome. I have been looking out for stuff wrt legacy db. For us it doesnt make sense to change the db structure for Grails but we need something similar. I will go thru the links

You are right Peter, we have been using Hibernate XML mapping files and ROI is still under question
 
Denis Wang
Ranch Hand
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd be surprised if people are still struggling with Grails + Legacy Database. This link provides very easy to use sample code and straightforward tricks.
http://denistek.blogspot.com/2009/12/grails-and-legacy-database.html
 
Vyas Sanzgiri
Ranch Hand
Posts: 686
Chrome Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Denis, as I said earlier...you are talking about very simple legacy tables. In any enterprise environment we expect complex primary keys - composite keys, Keys which are not string but complex objects.

Grails - out of the box does not support this nor do the plugins. I have to change lot of code in the controller for the CRUD to work. Don't even talk about the plugins!
 
Denis Wang
Ranch Hand
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mind to share your sample code here?
I run into the same issue and look for a solution now.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic