0

我有以下两个类,一个 ReqCandAssociation 可以有很多评论,它的映射是这样的。我需要找到一种方法,当我删除 ReqCandAssociation 时,它会删除所有相关的评论。谢谢

@Entity
@Table(name = "candidate_jobReq")
public class ReqCandAssociation implements Serializable {

@Id
private Integer candidateId;

@Id
private Integer jobId;

@Column(name = "reqStatus")
private String reqStatus;

@ManyToOne
@PrimaryKeyJoinColumn(name="candidateId", referencedColumnName="id")
private Candidate candidate;

@ManyToOne
@PrimaryKeyJoinColumn(name="jobId", referencedColumnName="id")
private JobReq jobReq;

public ReqCandAssociation(){

}

二等舱

@Entity
@Table(name="comment")

 public class Comment {

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer id; 

@Column(name="commentText")
private String commentText;

@Column(name="commentDate")
private Date commentDate;

@ManyToOne
@PrimaryKeyJoinColumn(name="reqCandAssociationId", referencedColumnName="id")
private ReqCandAssociation reqCandAssociation;

@ManyToOne
@PrimaryKeyJoinColumn(name="userId", referencedColumnName="id")
private User user;
4

1 回答 1

1

将其更改为以下内容,我正在使其成为双向映射。

@Entity
@Table(name = "candidate_jobReq")
public class ReqCandAssociation implements Serializable {

@Id
private Integer candidateId;

@Id
private Integer jobId;

@Column(name = "reqStatus")
private String reqStatus;

@OneToMany(cascade = { CascadeType.ALL }) //this is added here.
@JoinColumn(name ="reqCandAssociationId")
private Set<Comment> comments;
-----

阅读有关级联选项的更多信息。所有级联类型均为 all|none|save-update|delete|all-delete-orphan|delete-orphan

级联全部将删除与该类关联的所有评论。

于 2013-10-03T20:07:57.987 回答