Amir Khawaja
Amir Khawaja

Reputation: 469

In Grails, how do I declare a SQL Server Schema name for a Domain Class?

I have recently started reading up on Grails and would like to use SQL Server security schemas to group tables generated by GORM. However, I cannot seem to find a reference explaining how to perform this task. I am new to Hibernate as well and would like to know if this is possible. Thank you.

Upvotes: 5

Views: 2918

Answers (2)

Nathan Crause
Nathan Crause

Reputation: 943

The answer given by Michael Borgwardt is technically correct, but be aware that as of Grails 1.3.4, there is still a bug where using table-per-class inheritance all child classes will ignore the schema definition.

A possible work-around is to name the entire table and include the schema thus: "dbo.books", however this can cause problems with referential integrity; GORM will try to construct a name which contains too many "." characters, and PostgreSQL (for one) thinks you're trying to create cross-database server referential integrity, which isn't supported.

Upvotes: 0

Michael Borgwardt
Michael Borgwardt

Reputation: 346240

You can do this when you explicitly specify the mapping in a domain class as described here:

class Book {
    static mapping = {
        table name:"books", schema:"dbo"
    }
}

Upvotes: 12

Related Questions