如何在复合键中使用生成的值?
2022-09-03 15:17:43
我有两个类 documentlog 和 documentversion(带有主键:int doc_id 和 int docVersionID),具有多对一关系。我使用了一个名为 CompundKey 的复合键类来管理复合主键。我需要自动递增文档版本ID,但我无法做到这一点。在这方面,你能帮帮我吗?
@Entity
@Table(name = "Documentversion", schema = "DocumentManagement")
public class DocumentVersion implements Serializable {
private CompoundKey id;
private List<DocumentLog> documentLog;
@OneToMany(mappedBy="documentVersion", targetEntity=DocumentLog.class,
cascade ={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
public List<DocumentLog> getDocumentLog() {
return documentLog;
}
public void setDocumentLog(List<DocumentLog> documentLog) {
this.documentLog = documentLog;
}
@EmbeddedId
@AttributeOverride(name="doc_Id", column=@Column(name="doc_Id") )
public CompoundKey getId() {
return id;
}
public void setId(CompoundKey id) {
this.id = id;
}
}