我将Spring Boot 2,spring-data-jpa和hibernate一起使用
我有一对一的单向关系
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class Samplings {
@Id
@GenericGenerator(name = "samplings_id_seq", strategy = "com.lcm.model.SamplingSequenceGenerator")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "samplings_id_seq")
private Integer id;
@OneToOne(optional = false)
private Products product;
...
}
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class Products extends BaseEntity {
@Id
@SequenceGenerator(name = "products_id_seq", sequenceName = "products_id_seq", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "products_id_seq")
private Integer id;
...
}
为什么冬眠为我创建了这个约束?
alter table if exists lcm.samplings
add constraint UK_oofms38wiq2q4v0w40a2qdk6f unique (product_id);
我必须能够执行这种情况
用乘积y采样x 用乘积y采样z
实际上添加了休眠限制,我不能,我不明白吗?