描述
我有一个系统,我可以在其中添加Component并将其保存到 DB(Mysql)。之后,可以创建Product一个包含Components不同数量的罐子。据我了解,表应该是component_id|product_id|amount_of_component
组件类:
@Entity
@Table(name = "component")
public class Component {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
}
产品类别:
@Entity
@Table(name = "product")
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
//something should be here
private Component component;
}
问题
我应该使用哪个注释或集合来在这些实体之间创建这种关系?