I get this error, when trying to connect two table via manytomany: ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] Unsuccessful: alter table PARAM_TRENDVALUE add constraint FK_TrendValue foreign key (AreaID, PcID, DeviceID, ValueID) references usrIFDBMaster.tblTrdProcessValues 08:44:43,800 ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] Die 'usrIFDBMaster.tblTrdProcessValues.DeviceID'-Spalte hat nicht denselben Datentyp wie die verweisende 'PARAM_TRENDVALUE.PcID'-Spalte im 'FK_TrendValue'-Fremdschlüssel.
Principaly hibernate is trying to map the wrong columns.
Param.java:
This is the key:
@EmbeddedId
@AttributeOverrides( {
@AttributeOverride(name = "pcId", column = @Column(name = "PcID", nullable = false)),
@AttributeOverride(name = "unitId", column = @Column(name = "UnitID", nullable = false)),
@AttributeOverride(name = "paramId", column = @Column(name = "ParamID", nullable = false)) })
public ParamId getId() {
return this.id;
}
This is the mapping:
/**
* @return the connection
*/
@ManyToMany
@ForeignKey(name = "FK_Param")
@JoinTable(
name="PARAM_TRENDVALUE",
inverseJoinColumns={
@JoinColumn(name = "PcID", referencedColumnName = "PcID"),
@JoinColumn(name = "AreaID", referencedColumnName = "AreaID"),
@JoinColumn(name = "DeviceID", referencedColumnName = "DeviceID"),
@JoinColumn(name = "ValueID", referencedColumnName = "ValueID")
}
)
public List<TrendValue> getTrendValues() {
return trendValues;
}
Trendvalue.java:
This is the key:
@EmbeddedId
@AttributeOverrides( {
@AttributeOverride(name = "pcId", column = @Column(name = "PcID", nullable = false)),
@AttributeOverride(name = "areaId", column = @Column(name = "AreaID", nullable = false)),
@AttributeOverride(name = "deviceId", column = @Column(name = "DeviceID", nullable = false)),
@AttributeOverride(name = "valueId", column = @Column(name = "ValueID", nullable = false))
})
public TrendValueId getId() {
return this.id;
}
This is the mapping:
/**
* @return the params
*/
@ManyToMany(
mappedBy="trendValues",
targetEntity=Param.class
)
@ForeignKey(name = "FK_TrendValue")
public List<Param> getParams() {
return params;
}
It´s the first manytomany I try to use, and it should work, I already tried without inversejoincolumns, with joincolumns, defining exactly the tables and datatypes in "joincolumns/inversejoincolumns", ... Don't know what else could be the problem.