Untitled
unknown
java
a year ago
1.5 kB
4
Indexable
@Data
@NoArgsConstructor
@Entity
public class Applicant {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@OneToOne
@JoinColumn(name = "cv_id", referencedColumnName = "id")
private Cv cv;
public Applicant(Cv cv) {
this.cv = cv;
}
}
@Data
@NoArgsConstructor
@Entity
public class Education {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@ManyToOne
@JoinColumn(name = "cv_id", referencedColumnName = "id")
private Cv cv;
public Education(Cv cv) {
this.cv = cv;
}
}
@Data
@NoArgsConstructor
@Entity
public class Cv {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@OneToOne(mappedBy = "cv", cascade = CascadeType.ALL)
private Applicant applicant;
@OneToMany(mappedBy = "cv", cascade = CascadeType.ALL)
private Set<Education> educations = new HashSet<>();
@OneToMany(mappedBy = "cv", cascade = CascadeType.ALL)
private Set<Experience> experiences = new HashSet<>();
public Cv(Applicant applicant, Set<Education> educations, Set<Experience> experiences) {
this.applicant = applicant;
this.educations = educations;
this.experiences = experiences;
}
}
public Cv save(Cv cv) {
return cvRepository.save(cv);
}
// Hibernate: insert into cv (id) values (default)
// Hibernate: insert into applicant (cv_id,id) values (?,default)
// Hibernate: insert into education (cv_id,id) values (?,default)
Editor is loading...
Leave a Comment