【发布时间】:2021-08-26 01:10:20
【问题描述】:
我有两个表作为表
@Entity
@Table(name = "product", uniqueConstraints=@UniqueConstraint(columnNames={"product_idn"}))
public class Product implements Serializable {
private static final long serialVersionUID = 21409635044L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String product_idn;
}
另一个表
@Entity
@Table(name = "storage")
public class Storage implements Serializable {
private static final long serialVersionUID = -67165579239L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "product_id", nullable = false)
@JsonBackReference
private Product product;
}
现在我正在从 storage 表中获取记录。是否应该在存储表的 product_id 上创建索引(非唯一)?我必须根据产品获取存储数量/根据产品获取存储。
【问题讨论】:
标签: mysql hibernate jpa spring-data-jpa