4

I'm writing a Grails application that will be pulling data from an existing Oracle database. If I were designing this from scratch I could hold all the information in two or three domain models because logically that's how the data should be arranged. However, this is a pre-existing database that has the data I need spread across approximately 25-30 tables. So I am wondering which of the following approaches would be considered best. I don't want to do tons of extra work to take advantage of what Grails has to offer, but at the same time I'd like to take advantage of as much of Grails as possible.

  1. Create domain models for all 25-30 tables and then gather the data into two or three classes.
  2. Create the two or three domain models and populate them "manually" with SQL calls
  3. Since I'm new to Grails and how it handles data, something else that I haven't thought of yet.
Harry Muscle
  • 2,247
  • 4
  • 38
  • 62
  • What about adding views to the db and building at least parts of the domain model against that? Funny you ask, I just run across an article on that. http://java.dzone.com/articles/using-database-views-grails – vector Jan 28 '14 at 02:16
  • Unfortunately making any changes to the db is not possible ... this includes adding views. – Harry Muscle Jan 28 '14 at 02:49
  • ... that is unfortunate. – vector Jan 28 '14 at 02:52

1 Answers1

2

There is one answer to all of your queries:

database-reverse-engineer plugin

You can configure the way you want to reverse engineer the tables to domain classes. Refer docs as well.

dmahapatro
  • 49,365
  • 7
  • 88
  • 117
  • As far as I can tell (and please correct me if I'm wrong) that plug in creates one class per table, so that would work for option 1. – Harry Muscle Jan 28 '14 at 02:49
  • Works both for option 1 and 3. :) I believe starting with baby steps, then you can think of creating views and sophisticating your model etc gradually. Above all, it is easily testable. – dmahapatro Jan 28 '14 at 02:52