所以我有“OrderItem”类。它的主键假设由“productID”和“orderID”(来自另一个实体的 FK 引用)组成。如何使用注释进行设置?
提前致谢!!!!
表:ordersItems
属性:productID (PK-PK) ------> 产品
orderID (PK-PK) ------------- -----> 订购
鉴于这些实体:
@Entity
@Table(name="products")
public class Product {
@Id
@Column(name="productID")
private Integer id;
private String description;
}
@Entity
@Table(name="orders")
public class Order{
@Id
private int orderID;
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
@JoinColumn(name="orderID")
private List<OrderItem> items;
}
@Entity
@Table(name="ordersItems")
public class OrderItem{
@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
@JoinColumn(name="productID")
private Product product;
private int quantity;
private float price;
}