Search code examples
mysqlgrailsgrails-orm

How to use your own database structure in Grails?


We have an Android-Application communicating with a MySQL database via SOAP.

Now we were forced to create a webpage with Grails and of course we want to use the same database. But how can we tell Grails to use our database structure for the domains? Is there a way to merge these systems?

(The connection to the MySQL-Database is already established, but the two structures do not work together)

e.g. (in the least complicated case) we have a table "locations" with just one column 'name' which is PK. Grails would create a structure for the domain "location" with three columns 'id' 'version' and 'name'.


Solution

  • GORM allows you a lot of configurations, you can disable the version control, change your primary key mapping and so on. In your example:

    class Locations {
      String name
    
      static mapping = {
        id column: 'name' //change the id from "id" to name
        version false //remove version control, so it will not be added to your table
      }
    
    }