我有一个实体,例如A包含3个字段作为复合键,其中id是序列生成的:
@Entity
@IdClass(APK.class)
public class A extends AbstractEntity {
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "_A_SEQ")
@SequenceGenerator(name = "A_SEQ", sequenceName= "A_SEQ", allocationSize = 1)
private Integer a1;
@Id
private Integer a2;
@Id
private String a3;
....
@ManyToOne
@JoinColumns({
@JoinColumn(name = "a1", referencedColumnName = "b1", insertable = false, updatable = false),
@JoinColumn(name = "a2", referencedColumnName = "b2", insertable = false, updatable = false)
})
private B b;
因此,作为a1,a1,a3是复合键的一部分,我可以例如: 1222,1," s", 1222,1," m" - 初选,因为他们是R uniq。但!当我持久化一个新实体时,我无法实现这样的情况 - 生成a1(但这次我不需要它)。怎么避免这个?
然后如何更好地满足A和B,如果A有3个部分主要a1,a2,a3(很多)和B只到字段(b1到a1和b2到a2)(一个),例如: 在A(a1,a2,a3)中:
(b1,b2): 1222,1
谢谢!