请考虑以下情形。 有产品(例如蛋糕,杯子蛋糕,松饼等),字段“id”,“name”,“price”。 订单可以包含多个具有数量的产品。在关系数据库中,它应该是3个表。订单,产品和订单_产品(orderId和productId为primaryKey和“数量”列)。但我不确定这种情况下JPA的关系。
订单和产品之间的关系需要是一对多的。但是在“数量”(产品数量)应该到来的地方我很困惑。
订单实体
@Entity
public class MyOrder implements Serializable
{
@Id
@GeneratedValue
private Long Id;
@OneToMany(mappedBy = "product")
private Set<Product> product;
}
产品实体
@Entity
public class Product implements Serializable
{
@Id
@GeneratedValue
private Long id;
private String name;
private double unitPrice;
}
谢谢。