0

我有一个名为 Test 的域,它一直在运行查找 SQL 查询以从另一个数据库中进行选择。

我想摆脱这种实现并转到 Grails 2.0 的多数据源支持。但是,另一个数据库中的表名是一个名为 Panel。

是否可以将域映射到备用数据库并映射它从哪个表中选择?

// Datasource.groovy
development {
    dataSource {
        dbCreate = 'create-drop' // one of 'create', 'create-drop','update'
        url = "jdbc:sqlserver://machine\\SQLEXPRESS;databaseName=primarydb"
        username = "user"
        password = "password"
    }
    dataSource_otherdb {
        url = "jdbc:sqlserver://remoteserver:1433;databaseName=otherdb"
    }
}

// Test.groovy
class Test {

    String name
    int key
    String abbreviation

    boolean active = true

    static mapping = {
        sort name: "asc"
        datasource("otherdb")
    }
}
4

1 回答 1

2

映射闭包中有一个“表”配置。

// Test.groovy
class Test {

    String name
    int key
    String abbreviation

    boolean active = true

    static mapping = {
        table 'Panel'        //customize table name
        sort name: "asc"
        datasource("otherdb")
    }
}
于 2012-12-13T06:13:24.567 回答