业务场景: 一个商品对应多个仓存,需要查询商品在某个或某几个库存中存在时,查询出来.
实体类 ,商品Goods
@Entity
@Table(name = "es_goods")
public class Goods {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "goods_id")
private Integer id;
private String name;
//仓库集合
@OneToMany(mappedBy = "goods", cascade = CascadeType.ALL)
private List<ProductStore> productStores;
}
实体类,仓库
@Entity
@Table(name = "es_product_store")
public class ProductStore {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "id")
private Integer id;
//商品
@ManyToOne
@JoinColumn(name="goods_id")
private Goods goods;
//仓库