引起原因:org.hibernate.AnnotationException:maptedBy引用了未知的目标实体属性: [英] Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property:

查看:97
本文介绍了引起原因:org.hibernate.AnnotationException:maptedBy引用了未知的目标实体属性:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 @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.Purveyor.deliveries中的x.Delivery.deliveries

Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: x.Delivery.deliveries in x.Purveyor.deliveries

我尝试了此站点中已经提到的解决方案,但对我而言不起作用.

I tried the solutions already mentionned in this site but it doesn't work for me.

有人可以帮助我解决此问题吗?

Can anybody helps me to resolve this issue

推荐答案

消息非常清晰.您是对JPA说的:这个OneToMany是Delivery实体中通过字段deliveries定义的ManyToOne的反面.但是Delivery中没有字段deliveries.交付中的相应字段名为purveyor:

The message is pretty clear. You're saying to JPA: this OneToMany is the inverse side of the ManyToOne, defined in the Delivery entity, by the field deliveries. But there is no field deliveries in Delivery. The corresponding field in Delivery is named 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")

这篇关于引起原因:org.hibernate.AnnotationException:maptedBy引用了未知的目标实体属性:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆