I have a table called conclusion and it has a relationship with table comments.
When i am adding conclusion and comments at the same time, Conclusion is being inserted but child getting conclusion id as null by which i'm getting violation of not null constraint. My transaction roll backs conclusion also not inserted.
So please tell me how to insert parent and child at once.
my entities are
Conclusion Entity
@Entity
@Table(name="olm_anlys_cncln")
public class OlmAnalysisConclusion implements Serializable {
private static final long serialVersionUID = 1L;
private Long conclusionId;
private String concludedBy;
private Timestamp concludedTime;
private String conclusion;
private Timestamp discussionEndTime;
private String discussionActive;
private Timestamp discussionStartTime;
private Integer tntId;
private OlmAnalysis olmAnly;
private OlmAnalysisCategory olmAnlysCatgMstr;
private OlmAnalysisCause olmAnlysCauseMstr;
private List<OlmInvsgDiscussionComment> olmInvsgDiscnCmnts;
public OlmAnalysisConclusion() {
}
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="olm_anlys_cncln_id")
public Long getConclusionId() {
return this.conclusionId;
}
public void setConclusionId(Long conclusionId) {
this.conclusionId = conclusionId;
}
@Column(name="cncld_by")
public String getConcludedBy() {
return this.concludedBy;
}
public void setConcludedBy(String concludedBy) {
this.concludedBy = concludedBy;
}
@Column(name="cncld_time")
public Timestamp getConcludedTime() {
return this.concludedTime;
}
public void setConcludedTime(Timestamp concludedTime) {
this.concludedTime = concludedTime;
}
@Column(name="cncln")
public String getConclusion() {
return this.conclusion;
}
public void setConclusion(String conclusion) {
this.conclusion = conclusion;
}
@Column(name="discn_end_time")
public Timestamp getDiscussionEndTime() {
return this.discussionEndTime;
}
public void setDiscussionEndTime(Timestamp discussionEndTime) {
this.discussionEndTime = discussionEndTime;
}
@Column(name="discn_flag")
public String getDiscussionActive() {
return this.discussionActive;
}
public void setDiscussionActive(String discussionActive) {
this.discussionActive = discussionActive;
}
@Column(name="discn_strt_time")
public Timestamp getDiscussionStartTime() {
return this.discussionStartTime;
}
public void setDiscussionStartTime(Timestamp discussionStartTime) {
this.discussionStartTime = discussionStartTime;
}
@Column(name="tnt_id")
public Integer getTntId() {
return this.tntId;
}
public void setTntId(Integer tntId) {
this.tntId = tntId;
}
//bi-directional many-to-one association to OlmAnalysis
@ManyToOne
@JoinColumn(name="anlys_id")
public OlmAnalysis getOlmAnly() {
return this.olmAnly;
}
public void setOlmAnly(OlmAnalysis olmAnly) {
this.olmAnly = olmAnly;
}
//bi-directional many-to-one association to OlmAnalysisCategory
@ManyToOne
@JoinColumn(name="catg_id")
public OlmAnalysisCategory getOlmAnlysCatgMstr() {
return this.olmAnlysCatgMstr;
}
public void setOlmAnlysCatgMstr(OlmAnalysisCategory olmAnlysCatgMstr) {
this.olmAnlysCatgMstr = olmAnlysCatgMstr;
}
//bi-directional many-to-one association to OlmAnalysisCause
@ManyToOne
@JoinColumn(name="cause_id")
public OlmAnalysisCause getOlmAnlysCauseMstr() {
return this.olmAnlysCauseMstr;
}
public void setOlmAnlysCauseMstr(OlmAnalysisCause olmAnlysCauseMstr) {
this.olmAnlysCauseMstr = olmAnlysCauseMstr;
}
//bi-directional many-to-one association to OlmInvsgDiscussionComment
@OneToMany(fetch=FetchType.EAGER,mappedBy="olmAnlysCncln",cascade=CascadeType.ALL)
public List<OlmInvsgDiscussionComment> getOlmInvsgDiscnCmnts() {
return this.olmInvsgDiscnCmnts;
}
public void setOlmInvsgDiscnCmnts(List<OlmInvsgDiscussionComment> olmInvsgDiscnCmnts) {
this.olmInvsgDiscnCmnts = olmInvsgDiscnCmnts;
}
public OlmInvsgDiscussionComment addOlmInvsgDiscnCmnt(OlmInvsgDiscussionComment olmInvsgDiscnCmnt) {
getOlmInvsgDiscnCmnts().add(olmInvsgDiscnCmnt);
olmInvsgDiscnCmnt.setOlmAnlysCncln(this);
return olmInvsgDiscnCmnt;
}
public OlmInvsgDiscussionComment removeOlmInvsgDiscnCmnt(OlmInvsgDiscussionComment olmInvsgDiscnCmnt) {
getOlmInvsgDiscnCmnts().remove(olmInvsgDiscnCmnt);
olmInvsgDiscnCmnt.setOlmAnlysCncln(null);
return olmInvsgDiscnCmnt;
}
}
Comment Entity
@Entity
@Table(name="olm_invsg_discn_cmnt")
public class OlmInvsgDiscussionComment implements Serializable {
private static final long serialVersionUID = 1L;
private Long commentId;
private String comment;
private Timestamp commentTime;
private String commentedBy;
private Integer tenentId;
private OlmAnalysisConclusion olmAnlysCncln;
private Set<OlmInvsgCommentAttachment> olmInvsgDiscnCmntAtmnts;
public OlmInvsgDiscussionComment() {
}
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="olm_invsg_discn_cmnt_id")
public Long getCommentId() {
return this.commentId;
}
public void setCommentId(Long commentId) {
this.commentId = commentId;
}
@Column(name="cmnt")
public String getComment() {
return this.comment;
}
public void setComment(String comment) {
this.comment = comment;
}
@Column(name="cmnt_time")
public Timestamp getCommentTime() {
return this.commentTime;
}
public void setCommentTime(Timestamp commentTime) {
this.commentTime = commentTime;
}
@Column(name="cmntd_by")
public String getCommentedBy() {
return this.commentedBy;
}
public void setCommentedBy(String commentedBy) {
this.commentedBy = commentedBy;
}
@Column(name="tnt_id")
public Integer getTenentId() {
return this.tenentId;
}
public void setTenentId(Integer tenentId) {
this.tenentId = tenentId;
}
//bi-directional many-to-one association to OlmAnalysisConclusion
@ManyToOne(fetch=FetchType.EAGER, optional=false)
@JoinColumn(name="cncln_id")
public OlmAnalysisConclusion getOlmAnlysCncln() {
return this.olmAnlysCncln;
}
public void setOlmAnlysCncln(OlmAnalysisConclusion olmAnlysCncln) {
this.olmAnlysCncln = olmAnlysCncln;
}
//bi-directional many-to-one association to OlmInvsgCommentAttachment
@OneToMany(fetch=FetchType.EAGER,mappedBy="olmInvsgDiscnCmnt",cascade=CascadeType.ALL)
public Set<OlmInvsgCommentAttachment> getOlmInvsgDiscnCmntAtmnts() {
return this.olmInvsgDiscnCmntAtmnts;
}
public void setOlmInvsgDiscnCmntAtmnts(Set<OlmInvsgCommentAttachment> olmInvsgDiscnCmntAtmnts) {
this.olmInvsgDiscnCmntAtmnts = olmInvsgDiscnCmntAtmnts;
}
public OlmInvsgCommentAttachment addOlmInvsgDiscnCmntAtmnt(OlmInvsgCommentAttachment olmInvsgDiscnCmntAtmnt) {
getOlmInvsgDiscnCmntAtmnts().add(olmInvsgDiscnCmntAtmnt);
olmInvsgDiscnCmntAtmnt.setOlmInvsgDiscnCmnt(this);
return olmInvsgDiscnCmntAtmnt;
}
public OlmInvsgCommentAttachment removeOlmInvsgDiscnCmntAtmnt(OlmInvsgCommentAttachment olmInvsgDiscnCmntAtmnt) {
getOlmInvsgDiscnCmntAtmnts().remove(olmInvsgDiscnCmntAtmnt);
olmInvsgDiscnCmntAtmnt.setOlmInvsgDiscnCmnt(null);
return olmInvsgDiscnCmntAtmnt;
}
}