我試圖通過manytomany連接兩個表時出現此錯誤: ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] Unsuccessful:alter table PARAM_TRENDVALUE add constraint FK_TrendValue foreign key(AreaID,PcID, DeviceID,ValueID)引用usrIFDBMaster.tblTrdProcessValues 08:44:43,800錯誤[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。hibernate註解錯誤映射
Principaly hibernate試圖映射錯誤的列。
Param.java:
這是關鍵的:
@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;
}
這是映射:
/**
* @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:
這是關鍵的:
@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;
}
這是映射:
/**
* @return the params
*/
@ManyToMany(
mappedBy="trendValues",
targetEntity=Param.class
)
@ForeignKey(name = "FK_TrendValue")
public List<Param> getParams() {
return params;
}
It's第一多對多我嘗試使用,它應該工作,我已經嘗試過沒有inversejoincolumns,與joincolumns,正是在定義「joincolumns表和數據類型/ inversejoincolumns「,... 不知道還有什麼可能是問題。
謝謝你的回答,試過了,但沒有改變我的問題,同樣的錯誤。我查了一下hibernate試圖做的數據庫連接,他試圖將AreaID與AreaID =>正確,DeviceID與PcID =>不正確,ValueID與DeviceID =>不正確,PcID與ValueID =>不正確 – Charles 2012-02-06 08:16:16
性別歧視評論:I很高興這是一個ManyToMany而不是OneToMany :-) – 2014-10-08 12:17:02