有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在复合键中使用生成的值?

我有两个类documentlog和documentversion(主键为int doc_id和int docVersionID),它们之间有多对一的关系。我使用了一个名为CompundKey的复合密钥类来管理复合主键。我需要自动增加docversionID,但我不能这样做。在这方面你能帮我吗

@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;
 } 
}

共 (0) 个答案