class Tooth {
Integer id
ToothDisease toothDisease
static mapping = {
table name: 'AK_TOOTH'
id generator: 'sequence', params: [sequence: 'SEQ_AK_TOOTH']
columns{
toothDisease {
column: 'FK_AK_TOOTH_ID'
column: 'FK_AK_TOOTH_NR_VERSION'
}
}
}
class ToothDisease implements Serializable{
Integer idColumn
Integer nrVersion
static mapping = {
table name: 'AK_TOOTH_DISEASE'
idColumn column: 'ID', generator: 'sequence', params: [sequence: 'SEQ_AK_TOOTH_DISEASE']
nrVersion column: 'NR_VERSION',
id composite ['idColumn','nrVersion']
int hashCode() {
def builder = new HashCodeBuilder()
builder.append (idColumn)
builder.append (nrVersion)
builder.toHashCode()
}
boolean equals (other) {
if (other == null) {
return false
}
def builder = new EqualsBuilder()
builder.append (idColumn, other.idColumn)
builder.append (nrVersion, other.nrVersion)
builder.isEquals()
}
}
Lorsque je tente de bootRun mon application, je me BeanCreationException:Grails 3.1.6, Hibernate 4. clé étrangère composite
Caused by: org.hibernate.MappingException: Foreign key (FK_1rnajvolkf4rkav5w1hl0l9fk:AK_TOOTH [tooth_disease_id,FK_AK_TOOTH_ID,FK_AK_TOOTH_NR_VERSION,tooth_disease_id_column,tooth_disease_nr_version])) must have same number of columns as the referenced primary key (AK_TOOTH_DISEASE [ID,NR_VERSION]).
Lorsque j'ai retiré section de mappage de colonne dans la dent, puis je suis arrivé la même erreur sans ces colonnes
[tooth_disease_id,tooth_disease_id_column,tooth_disease_nr_version].
Est-il possible de définir explicitement une colonne de clé et un nomColumn référencé comme en hibernation? Pourquoi il y a trois colonnes? en particulier tooth_disease_id and tooth_disease_id_column columns
dans le même temps. J'ai essayé d'utiliser le nom « primaryKey » comme clé primaire composite pour dent et « id » simple colonne id, mais de cette façon, j'ai eu la même erreur
Caused by: org.hibernate.MappingException: Foreign key (FK_1rnajvolkf4rkav5w1hl0l9fk:AK_TOOTH [tooth_disease_id,FK_AK_TOOTH_ID,FK_AK_TOOTH_NR_VERSION,tooth_disease_id_column,tooth_disease_nr_version])) must have same number of columns as the referenced primary key (AK_TOOTH_DISEASE [ID]).But there is only one referenced primary key.
Malheureusement, je n'ai aucune chance de changer la structure du schéma et évitez la clé composite.
Nous vous remercions de la réponse, mais il n 'me aider. Toujours la même erreur avec trois colonnes pour la clé étrangère. –