Sunday, December 5, 2010

Grails Domain Objects Across Schemas

The Grails documentation is very clear on how to specify specific table and column names for your domain classes (in Section 5.5.2 Custom ORM Mapping). But what if you need to specify the schema as well? Fortunately it is just as easy, if less well-documented.

class Book {
static mapping = {
table name:'my_books', schema:'book_admin'
}
}
view raw book.groovy hosted with ❤ by GitHub


Of course, when all of your domain tables are in the same schema, you should simply specify a default schema in DataSource.groovy. The property is hibernate.default_schema.