【问题标题】:Set datasource 'ALL' for all grails domain mapping GORM为所有 grails 域映射 GORM 设置数据源“ALL”
【发布时间】:2015-12-11 20:49:32
【问题描述】:

我想添加其他数据源以与 GORM 一起使用。

DataSource.groovy

development {
    dataSource {
        dbCreate = "update"
        driverClassName = "org.postgresql.Driver"
        username = "usrcastor"
        url = "jdbc:postgresql://localhost:5432/dbcastor_master"
        password = "castor"
        dialect = net.sf.hibernate.dialect.PostgreSQLDialect
        pooled = true
        loggingSql = false


    }

    dataSource_otherDataSource {
        dbCreate = "update"
        driverClassName = "org.postgresql.Driver"
        username = "usrcastor"
        url = "jdbc:postgresql://localhost:5432/dbcastor_child_a"
        password = "castor"
        dialect = net.sf.hibernate.dialect.PostgreSQLDialect
        pooled = true
        loggingSql = false
    }
}

但是已经有很多领域类,我没有时间在每个类中定义静态映射。

Domain.groovy

static mapping {
    datasource 'ALL'
}

是否可以配置 grails 为所有域设置数据源“ALL”?

【问题讨论】:

    标签: grails grails-orm


    【解决方案1】:

    您可以在 grails-app/conf/application.groovy 中添加类似的内容

    grails.gorm.default.mapping = {
        datasource 'ALL'
    }
    

    请参阅documentation 了解 Grails 映射。

    【讨论】:

    • id generator: 'sequence' 这样的属性可以正常工作,但忽略datasource 'ALL'
    • 如果我在 grails 2.4.3 中忽略了这一点。
    猜你喜欢
    • 1970-01-01
    • 2013-01-02
    • 1970-01-01
    • 2016-06-01
    • 2013-09-17
    • 2014-05-08
    • 1970-01-01
    • 2022-11-23
    • 1970-01-01
    相关资源
    最近更新 更多