【发布时间】:2017-05-27 05:39:18
【问题描述】:
我的模型中有以下内容: 成品车
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
但如果我只使用一个 ManyToOne 注释,它可以正常工作,我没有混合我的注释并且我在我的班级中使用了 AccesType.property。
根据这个链接Multiple @ManyToOne fields pointing to same entity in JPA / Hibernate我想要完成的事情是可能的,那为什么我会出错?
最后: 我需要的是在我的成品车中有两个 monter 字段,但它们都来自同一个实体,名为 Monter。我可以通过使用不同的表来实现这一点,但这样做没有任何意义。
【问题讨论】:
-
你的表中的所有列都有吗?
-
什么意思?所有的表和列都是由hibernate创建的,所以如果映射没问题我认为应该没有问题
-
您希望数据库中的 inMonter 和 outMonter 有不同的列?
-
是的,我希望在我的成品汽车实体中有列 inMonter 和 outMonter。当我用一列执行此操作时,它可以工作,但有两个我有问题
-
你应该在 FinishedCar 类中有一个 outMonter 属性。你只有 InMonter。