我有两个实体:Product 和 Aisle。一个产品可以在一个或多个通道中,一个通道可以有一个或多个产品。
@Entity
public class Product{
@Id
private Long id;
private String name;
@ManyToMany
@JoinTable(name = "product_aisle",
joinColumns = { @JoinColumn(name = "product_id") },
inverseJoinColumns = { @JoinColumn(name = "aisle_id") })
private Set<Aisle> aisles = new HashSet<>();
/* getters, setters, equals and hashcode */
}
@Entity
public class Aisle{
@Id
private Long id;
private String row;
private String shelf;
@ManyToMany(mappedBy="aisles")
private Set<Product> products = new HashSet<>();
/* getters, setters, equals and hashcode */
}
我还有最后一个实体:推销员。销售员负责过道中的产品:
@Entity
public class Salesman{
@Id
private Long id;
private String name;
/* ManyToOne to ProductAisle ?*/
}
问题:如何使用“@ManyToOne”注释将销售员引用到自动创建的连接表 (ProductAisle)?
汪汪一只猫
人到中年有点甜
相关分类