【问题标题】:How can I map tables from different dataSources in Grails?如何在 Grails 中映射来自不同数据源的表?
【发布时间】:2018-09-28 05:39:55
【问题描述】:

如何在 Grails 中映射来自不同数据源的表?

class Classroom {
    static hasMany = [students : Student]
    static mapping = {
        datasource 'school'
    }
}

class Laboratory {
    static hasMany = [students : Student]
    static mapping = {
        datasource 'school'
    }
}

class Student {
    String name
    static mapping = {
        datasource 'person'
    }
}

如果三个表都来自同一个数据源,那么 Grails 会生成五个表,分别是classroomlaboratorystudentclassroom_studentlaboratory_student

这段代码给了我一个错误:An association from the table classroom_student refers to an unmapped class: registration.Student

我的问题是:

1) 我如何做到这一点?

2) classroom_studentlaboratory_student 将在哪个数据源中生成?

【问题讨论】:

    标签: grails datasource


    【解决方案1】:

    1) 我如何做到这一点?

    GORM 不支持跨数据源的关系。您必须编写自己的查询并自己跟踪关系。

    2) 数据源中的教室_学生和实验室_学生 会生成吗?

    无论您在何处创建它们(请参阅第 1 条的答案)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-25
      • 1970-01-01
      • 1970-01-01
      • 2017-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多