Grails 当一个数据库的键是另一个数据库的id时,如何从遗留数据库映射一对一关系
我很难将工作映射到一个对我来说是只读的遗留数据库,我有一个属于第三方的类客户机,第三方有一个客户机 这些表如下所示:Grails 当一个数据库的键是另一个数据库的id时,如何从遗留数据库映射一对一关系,grails,mapping,gorm,one-to-one,Grails,Mapping,Gorm,One To One,我很难将工作映射到一个对我来说是只读的遗留数据库,我有一个属于第三方的类客户机,第三方有一个客户机 这些表如下所示: Client ThirdParty --------------------- -------------------- third_party_rowid (key) rowid (key) static mapping
Client ThirdParty
--------------------- --------------------
third_party_rowid (key) rowid (key)
static mapping = {
datasource 'xxxxx'
table 'clients'
version false
id column: 'third_party_rowid'
thirdParthy column: 'third_party_rowid', insertable: false, updateable: false
....
}
客户机没有自己的id,第三方也没有对客户机的引用,因此当我尝试映射客户机时,会出现很多错误:
如果我尝试将客户机的id和客户机的第三方都映射到同一列,我会得到一个重复的列错误
static mapping = {
datasource 'xxxxx'
table 'clients'
version false
id column: 'third_party_rowid'
thirdParthy column: 'third_party_rowid'
....
}
如果我尝试将客户机id命名为“thirdParhy”,则会出现未知类型错误
static mapping = {
datasource 'xxxxx'
table 'clients'
version false
id name: 'thirdParthy'
thirdParthy column: 'third_party_rowid'
....
}
如果我尝试不给id一个参数,我会得到一个无效的id错误
static mapping = {
datasource 'xxxxx'
table 'clients'
version false
thirdParthy column: 'third_party_rowid'
....
}
我没什么主意了,有人能帮我画一下吗
谢谢 我发现了问题!,hibernate需要使用insert=“false”、update=“false”映射其中一个复制列 要在grails上实现这一点,必须将其添加到映射中,如下所示:
Client ThirdParty
--------------------- --------------------
third_party_rowid (key) rowid (key)
static mapping = {
datasource 'xxxxx'
table 'clients'
version false
id column: 'third_party_rowid'
thirdParthy column: 'third_party_rowid', insertable: false, updateable: false
....
}