在我的应用程序中,两个实体之间具有以下映射:
@Entity
public class Applicant {
private Integer id;
....
private Set<Document> documents;
... Getters and Setters ...
@OneToMany(fetch = FetchType.LAZY, mappedBy = "applicant", cascade = CascadeType.ALL)
public Set<Document> getDocuments() {
return documents;
}
public Applicant setDocuments(Set<Document> documents) {
this.documents = documents;
return this;
}
}
Run Code Online (Sandbox Code Playgroud)
和文件:
public class Document {
private Long id;
private Applicant applicant;
... Getters and Setters ...
@ManyToOne
public Applicant getApplicant() {
return applicant;
}
public Document setApplicant(Applicant applicant) {
this.applicant = applicant;
return this; …Run Code Online (Sandbox Code Playgroud)