@Entity
public class Purveyor implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int ref_purveyor;
@Column(unique = true)
private String purveyor_name;
@Column(unique = true)
private int purveyor_number;
@Column(unique = true)
private String adress;
@Column(unique = true)
private int fax;
/**
*
* @return This returns the purveyor's ID.
*/
public int getRef_purveyor() {
return ref_purveyor;
}
/**
*
* @param ref_purveyor
* This refers to the ID of the new purveyor.
*/
public void setRef_purveyor(int ref_purveyor) {
this.ref_purveyor = ref_purveyor;
}
/**
*
* @return This return the name of the purveyor.
*/
public String getPurveyor_name() {
return purveyor_name;
}
/**
*
* @param purveyor_name
* This refers to the new purveyor's name.
*/
public void setPurveyor_name(String purveyor_name) {
this.purveyor_name = purveyor_name;
}
/**
*
* @return This returns the purveyor's number.
*/
public int getPurveyor_number() {
return purveyor_number;
}
/**
*
* @param purveyor_number
* This refers to the new purveyor's number.
*/
public void setPurveyor_number(int purveyor_number) {
this.purveyor_number = purveyor_number;
}
/**
*
* @return This returns purveyor's adress.
*/
public String getAdress() {
return adress;
}
/**
*
* @param adress
* This refers to the new purveyor's adress.
*/
public void setAdress(String adress) {
this.adress = adress;
}
/**
*
* @return This returns the purveyor's fax.
*/
public int getFax() {
return fax;
}
/**
*
* @param fax
* This refers to new purveyor's fax.
*/
public void setFax(int fax) {
this.fax = fax;
}
/*@OneToMany(mappedBy = "orders")
private Collection<Order> orders = new ArrayList<Order>();*/
@OneToMany(fetch=FetchType.LAZY,mappedBy = "deliveries")
private List<Delivery> deliveries = new ArrayList<Delivery>();
/**
*
* @see Order This refers to purveyor's Orders.
*/
/*public Collection<Order> getOrders() {
return orders;
}*/
/**
*
* @param orders
* This refers to the orders of the purveyor.
*/
/*public void setOrders(Collection<Order> orders) {
this.orders = orders;
}*/
/**
*
* @see Delivery This refers to purveyor's deliveries
*/
public List<Delivery> getDeliveries() {
return deliveries;
}
/**
*
* @param deliveries
* This refers to the deliveries of the purveyor.
*/
public void setDeliveries(List<Delivery> deliveries) {
this.deliveries = deliveries;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
}
======================-------------------------------==============================
@Entity
` public class Delivery implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "delivery_ref")
@GeneratedValue
private int delivery_ref;
@Column(unique = true)
private Date delivery_date;
@Column
private int quantity;
/**
* @return This returns the reference of the delivery.
*/
public int getDelivery_ref() {
return delivery_ref;
}
/**
*
* @param delivery_ref
* This refers to the new delivery.
*/
public void setDelivery_ref(int delivery_ref) {
this.delivery_ref = delivery_ref;
}
/**
* @return This returns the delivery date.
*/
public Date getDelivery_date() {
return delivery_date;
}
/**
*
* @param delivery_date
* This refers to the new date of delivery.
*/
public void setDelivery_date(Date delivery_date) {
this.delivery_date = delivery_date;
}
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "ref_purveyor")
private Purveyor purveyor;
@OneToOne(mappedBy = "delivery", cascade = CascadeType.ALL)
private BillDelivery billD;
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public BillDelivery getBillD() {
return billD;
}
public void setBillD(BillDelivery billD) {
this.billD = billD;
}
public Purveyor getPurveyor() {
return purveyor;
}
public void setPurveyor(Purveyor purveyor) {
this.purveyor = purveyor;
}
}
引起:org.hibernate.AnnotationException:mappedBy引用未知的目标实体属性:x.Delivery.deliveries in x.Purveyor.deliveries
我尝试过在本网站中提到的解决方案,但它对我不起作用。
任何人都可以帮我解决这个问题
答案 0 :(得分:4)
信息很清楚。您对JPA说:这个OneToMany是在Delivery
实体中由字段deliveries
定义的ManyToOne的反面。但deliveries
中没有字段Delivery
。交货中的相应字段名为purveyor
:
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "ref_purveyor")
private Purveyor purveyor;
^-- this is the other side of the association
所以你需要的是
@OneToMany(fetch=FetchType.LAZY,mappedBy = "puveyor")
答案 1 :(得分:0)
您的映射应该如下所示
Purveyor {
@OneToMany(fetch=FetchType.LAZY,mappedBy = "purveyor")
private List<Delivery> deliveries = new ArrayList<Delivery>();
}
Delivery {
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "ref_purveyor")
private Purveyor purveyor;
}