我正在使用一个旧数据库,其中表A由3个组合键组成,表B由2个复合键组成,这与表A中的两个组合键相同
OnesolPeNames
class OnesolPeNames implements Serializable {
static mapping = {
table "ONESOL_pe_names"
id composite: ["division", "peid"]
columns{
division column: 'division', length: 8, sqlType: "char"
peid column: 'pe_id', length: 12, sqlType: "char"
peNameU column: 'pe_name_u', length: 50, sqlType: "char"
}
}
static hasMany = [ recoverySetups : RecoverySetup]
....
恢复设置
class RecoverySetup implements Serializable {
static mapping = {
table "recovery_setup"
id composite: ["division", "peid", "orgkey"]
columns {
division column: 'division', length: 10, sqlType: "char"
peid column: 'peid', length: 12, sqlType: "char"
orgkey column: 'org_key', length: 8, sqlType: "char"
oneSolName column: ['division', 'peid']
}
}
static belongsTo = [oneSolName: OnesolPeNames]
....
我正在尝试像这样访问OnesolPeNames。
recoverySetup.onesolPeNames.peNameU。
我收到以下错误
我将oneSolName列设置为
['division', 'peid']
,onesol_pe_names_division,onesol_pe_names_peid
来自哪里?难道我的组合密钥既是PK的一部分,又起着FK的作用,被称为“派生身份”?
最佳答案
我有一个类似的问题,我以这种方式解决了映射表:
class RecoverySetup implements Serializable {
static mapping = {
table "recovery_setup"
id composite: ["division", "peid", "orgkey"]
columns {
orgkey column: 'org_key', length: 8, sqlType: "char"
oneSolName {
column name: 'division'
column name: 'peid'
}
}
oneSolName updateable: false, insertable: false
}
static belongsTo = [oneSolName: OnesolPeNames]
...
}