29 January 2013

HOWTO: Grails / GORM + Oracle Schema

By simply adding schema to your domain classes, you won't be able to get it working in h2 afterwards. Here is how you fix that.

1. Update all your domain classes

grails-app/domain/Person.groovy
class Person {
        String name
static mapping = {
table name: 'PERSON', schema:"MYSCHEMA"
}
}

2. Update all your datasource

grails-app/conf/DataSource.groovy:
environments {
    development {
        dataSource {
            dbCreate = "create-drop"
            url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;INIT=CREATE SCHEMA IF NOT EXISTS MYSCHEMA"
        }


repeat that for the test environment also.

Putting this in writing because I wish I had this blog post a while ago.

1 comment: