【发布时间】:2012-03-31 02:21:53
【问题描述】:
我在我的应用程序中使用 Grails Datasources 插件,并且在持久化引用只读关联(父)类的 (chidl) 域类时遇到问题。例如:
/* Parent domain class; a read-only datasource using the Datasources plugin */
class Parent {
//...Some fields
}
/* Child domain class, referencing the parent class */
class Child
// Some fields
static hasOne = [parent:Parent]
}
当我尝试坚持我的子类时,我收到了这个错误
Cannot add or update a child row: a foreign key constraint fails
(`foo`.`child`, CONSTRAINT `FK38A5EE5F707D1A2B`
FOREIGN KEY (`id`) REFERENCES `parent` (`id`))
我注意到当启动时创建表时,Grails 会从(只读)datasource A 到我的本地(可写)datasource B 创建引用表的本地空副本。是否可以改为引用此表(及其新创建的 FK)?如果是这样,为什么它不对实际数据源(即datasource A)强制执行 FK 约束?
我对 Grails 还很陌生,在其他任何地方都无法找到此特定问题的解决方案,如果这听起来像个愚蠢的问题,请见谅
【问题讨论】:
标签: hibernate grails datasource