I'm trying to map a ManyToOne relationship with a composite key.
I'd like to be able to access the OnesolPeNames domain object from RecoverySetup like so recoverySetup.onesolPeNames.peNameU
I've added the following code to my RecoverySetup mapping.
oneSolution {
column name: 'division'
column name: 'peid'
};
Table A
class RecoverySetup implements Serializable {
static constraints = {
}
static mapping = {
table "recovery_setup"
id composite: ["division", "peid", "orgkey"]
columns{
division column: 'division'
peid column: 'peid'
orgkey column: 'org_key'
oneSolution {
column name: 'division'
column name: 'peid'
};
}
}
String division
String peid
String orgkey
OnesolPeNames oneSolution
}
Table B
class OnesolPeNames implements Serializable {
static constraints = {
}
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]
String division
String peid
String peNameU
}
I get the following exception
Caused by MappingException: Repeated column in mapping for entity: org.hri.pisr.domain.RecoverySetup column: division (should be mapped with insert="false" update="false")
I also found this SO post One-to-Many With Composite Keys and Different Column Names in Grails
static hasOne = [OnesolPeNames: 'oneSolution']
– christopher