我的情况是:带有子消息的实体父 MainSpeech。消息又是实体附件的父级。
我尝试通过添加具有两个新附件的新按摩来保留/合并现有的 MainSpeech。持久化/合并失败,因为 ID_MESSAGE 为空。ID_MESSAGE 是连接 Messages with Attachment 的外键。
//Entity MainSpeech
@OneToMany(fetch=FetchType.LAZY,cascade=CascadeType.ALL,mappedBy="mainSpeech")
public List<Messages> getMessages() {
return messages;
}
public void setMessages(List<Messages> messages) {
this.messages = messages;
}
//Entity Messages
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="ID_MAINSPEECH",nullable=false)
public MainSpeech getMainSpeech() {
return mainSpeech;
}
public void setMainSpeech(MainSpeech mainSpeech) {
this.mainSpeech = mainSpeech;
}
@OneToMany(fetch=FetchType.LAZY,cascade=CascadeType.ALL,mappedBy="messages")
public List<Attachments> getAttachments() {
return attachments;
}
public void setAttachments(List<Attachments> attachments) {
this.attachments = attachments;
}
//Entity Attachments
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="ID_MESSAGE",nullable=false)
public Messages getMessages() {
return messages;
}
public void setMessages(Messages messages) {
this.messages = messages;
}
GCT1015
慕田峪9158850
相关分类