映射实体时出错

时间:2014-02-26 13:12:31

标签: java jpa persistence

按照书籍Programming Google App Engine中给出的示例在两个实体OneToMany之间创建Book and BookReview关系。在书中它是这样做的:

@Entity(name="Book")
public class Book {
....

@OneToMany(cascade=CascadeType.ALL)
private List<BookReview> bookReviews;
}

然后像这样对书类进行反向引用:

@Entity(name="BookReview")
public class BookReview {
...
@ManyToOne(mappedBy="bookReviews")
private Book book;
}

但是当我尝试这个时

@Entity 
 public class Store {

@Id
String storeName;

@OneToMany
private List<Employee> employees;

}
////////////
@Entity
public class Employee {


@Id
int employeeId;

@ManyToOne(mappedBy="employees")
private Store store;

}

@ManyToOne(mappedBy="employees")标有错误"The attribute mappedBy is undefined for the annotation type ManyToOne"。它建议我使用cascade,fetch,optional,targetEntity中的一个。这里真的很混乱。使用Eclipse。

1 个答案:

答案 0 :(得分:-1)

任何体面的JPA文档都会告诉您1-N bidir关系需要 mappedBy 与集合一起。错误信息也非常清楚