我在我的模型如下: 成品车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