我正在試圖製作購物車的物品。用戶有多個項目,所以我這樣做: 我有一個@Entity @Table類項目,它實現Serializableorg.hibernate.AnnotationException映射錯誤
private User user;
...
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@OneToMany(cascade = ALL, fetch = FetchType.EAGER, mappedBy = "items")
@Column(nullable = true, updatable = false)
public User getUser() {
return user;
}
和User.java(@Entity @Table實現Serializable):
private List<Item> items;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
...
@ManyToOne
public List<Item> getItems() {
return items;
}
public void setItems(List<Item> items) {
this.items = items;
}
我得到的是這樣的錯誤:
Caused by: org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements: org.auction.model.Item.user"}}
你已經得到了你的註釋backwar DS。 '公開名單- getItems()'是OneToMany和'公共用戶getUser()'是ManyToOne –