【发布时间】:2016-03-16 13:56:27
【问题描述】:
我在处理多个数据源时遇到了一个简单配置的问题,我正在尝试将新实例保存到特定数据源中
我的数据源:
dataSources:
dataSource:
pooled: true
jmxExport: true
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
driverClassName: com.mysql.jdbc.Driver
username: root
password: Choice2016
dominio1:
pooled: true
jmxExport: true
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
driverClassName: com.mysql.jdbc.Driver
username: root
password: Choice2016
dominio2:
pooled: true
jmxExport: true
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
driverClassName: com.mysql.jdbc.Driver
username: root
password: Choice2016
我的域名
class Nxtt_reports {
Boolean favorite
static hasMany = [nxtt_report_histories: Nxtt_report_history, nxtt_user_reports: Nxtt_user_reports, nxtt_report_snapshots: Nxtt_report_snapshot]
static constraints = {
}
static mapping = {
datasource 'ALL'
}
}
当我这样做时,
def nxtt = Nxtt_reports.class
println(nxtt.dominio1.list())
我可以列出我想要的域中的数据,但如果我这样做
def nxtt = Nxtt_reports.class.newInstance()
nxtt.favorite = 0
nxtt.dominio2.save()
我收到了
没有这样的属性:dominio2 类:nexttreport.server.Nxtt_reports。堆栈跟踪如下: groovy.lang.MissingPropertyException:没有这样的属性:dominio2 类:nexttreport.server.Nxtt_reports
使用:
| Grails 版本:3.1.1 | Groovy 版本:2.4.5 | JVM版本:1.8.0_65
编辑
environments:
development:
dataSources:
dataSource:
dbCreate: update
url: jdbc:mysql://192.168.1.24:3306/nexttreport?useUnicode=yes&characterEncoding=UTF-8&useSSL=false
dominio1:
dbCreate: update
url: jdbc:mysql://192.168.1.24:3306/dominio1?useUnicode=yes&characterEncoding=UTF-8&useSSL=false
dominio2:
dbCreate: update
url: jdbc:mysql://192.168.1.24:3306/dominio2?useUnicode=yes&characterEncoding=UTF-8&useSSL=false
【问题讨论】:
-
你能更新帖子并添加你的环境数据源配置吗?
-
是的,我编辑了问题
标签: grails grails-orm grails-domain-class