2011-11-27 60 views
0

我有兩個班,我試圖聯繫起來,並在運行時我得到以下異常:Hibernate的雙向多到一個關聯錯誤

org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: BidProposal.parents in Parent.bidproposals 

任何人都可以在這裏找到的錯誤,我在好幾個小時......

的類是這樣的:

Parent.Java:

@Entity 
@Table(name = "parents") 
public class Parent extends User implements java.io.Serializable { 
    private Integer id; 
    private Set<BidProposal> bidproposals = new HashSet<BidProposal>(0); 

    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    @Column(name = "id", unique = true, nullable = false) 
    public Integer getId() { 
    return this.id; 
    } 

    public void setId(Integer id) { 
    this.id = id; 
    } 

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "parents") 
    public Set<BidProposal> getBidproposals() { 
    return this.bidproposals; 
    } 

    public void setBidproposals(Set<BidProposal> bidproposals) { 
    this.bidproposals = bidproposals; 
    } 

} 

和BidProposal.Java:

@Entity 
@Table(name = "bidproposal") 
public class BidProposal implements java.io.Serializable { 

    private Integer id; 
    private Parent parent; 
    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    @Column(name = "id", unique = true, nullable = false) 
    public Integer getId() { 
    return this.id; 
    } 

    public void setId(Integer id) { 
    this.id = id; 
    } 

    @ManyToOne(fetch = FetchType.LAZY) 
    @JoinColumn(name = "parent_id", nullable = false) 
    public Parent getParent() { 
    return this.parent; 
    } 

    public void setParent(Parent parent) { 
    this.parent = parent; 
    } 
} 
+1

你的mappedBy =「父母」,但在BidProposal成員被稱爲「父」 – esaj

回答

2

org.hibernate.AnnotationException:引用的mappedBy未知 目標實體屬性:在Parent.bidproposals BidProposal.parents

這意味着屬性父母找不到實體BidProposal

它應該是:

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "parent") 
public Set<BidProposal> getBidproposals() {  
    return this.bidproposals; 
} 
+0

耶穌基督我很小白,我認爲應該的mappedBy引用含班級名稱... – stdcall