我在我的模型如下: 成品車Hibernate映射多對一兩次
private ObjectProperty<InMonter> inMonter = new SimpleObjectProperty<>();
@ManyToOne
@JoinColumn(name = "in_Monter_Id",referencedColumnName="inMonterId")
public InMonter getInMonter() {
return inMonter.get();
}
public ObjectProperty<InMonter> inMonterProperty() {
return inMonter;
}
public void setInMonter(InMonter inMonter) {
this.inMonter.set(inMonter);
}
蒙特:
private List<FinishedCar> fCar;
@OneToMany(mappedBy ="inMonter")
public List<FinishedCar> getfCar() {
return fCar;
}
public void setfCar(List<FinishedCar> fCar) {
this.fCar = fCar;
}
我想要做到的是有這個映射一個更像這個時候:
private ObjectProperty<InMonter> outMonter = new SimpleObjectProperty<>();
@ManyToOne
@JoinColumn(name = "out_monter_id",referencedColumnName="inMonterId")
public InMonter getMonterOut() {
return outMonter.get();
}
public ObjectProperty<InMonter> monterOutProperty() {
return outMonter;
}
public void setMonterOut(InMonter outMonter) {
this.outMonter.set(outMonter);
}
這
private List<FinishedCar> OutCar;
@OneToMany(mappedBy ="outMonter")
public List<FinishedCar> getOutCar() {
return OutCar;
}
public void setOutCar(List<FinishedCar> OutCar) {
this.OutCar = OutCar;
}
當我嘗試有兩次這方面,我得到
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.atlas.model.FinishedCar.outMonter in com.atlas.model.InMonter.outCar
但如果我只使用一個多對一註釋它工作得很好,我不合羣,我的註解,我用AccesType.property上我的課。
並根據此鏈接Multiple @ManyToOne fields pointing to same entity in JPA/Hibernate我想完成什麼是可能的,那麼爲什麼我有一個錯誤?
最後: 我需要的是在我的成品車中有兩個獨特的領域,但他們都來自同一個實體,名爲蒙特。我可以通過使用不同的表格來實現這一點,但它無法做到這一點。
你有你的表中的所有列? – XtremeBaumer
你是什麼意思?所有的表和列都是通過休眠創建的,所以如果映射是好的,我認爲應該沒有問題 – ImRaphael
你想在inMonter和outMonter數據庫中使用不同的列? – XtremeBaumer