假如我有两个类她们存在一对多的管理。例如:
一般情况下级联维护在多的一方
在数据库操作过程中,例如保存FAX对象,就需要维护级联关系
//Service操作保存Fax 方法
这时候会连带把attachment保存。
pubic class Fax{
//...
@OneToMany(mappedBy = "fax", cascade = CascadeType.ALL)
private Set<AttachmentFile> attachmentFile;
//...
}
public class AttachmentFile{
//...
@ManyToOne
@JoinColumn(name = "fax_id")
private Fax fax;
//...
}
一般情况下级联维护在多的一方
在数据库操作过程中,例如保存FAX对象,就需要维护级联关系
//Service操作保存Fax 方法
public Fax createFax(Fax fax) {
fax.setCreateDate(new Date());
if (fax.getAttachmentFile() != null) {
Set<AttachmentFile> attachment = fax.getAttachmentFile();
for (AttachmentFile attachmentFile : attachment) {
attachmentFile.setFax(fax);
}
fax.setAttachmentFile(attachment);
}
this.save(fax);
return fax;
}
这时候会连带把attachment保存。
1063

被折叠的 条评论
为什么被折叠?



