I have a mapping like below in one of my entities. When trying to save this entity, if scrMSgLine id is already set and the cascade type is PERSIST then i got the "org.hibernate.PersistentObjectException: detached entity passed to persist: ScrMsgLine" exception. If i change the cascade type to MERGE then record is saved succesfully.
If scrMSgLine id is null and cascade type is MERGE then i got the "object references an unsaved transient instance - save the transient instance before flushing" exception.
So which cascade type should i use, what am i doing wrong ?
@ManyToOne(cascade = {CascadeType.PERSIST})
@JoinColumn(name = "MSG_LINE_ID")
@Where(clause = "DELETED_AT IS NULL")
public ScrMsgLine getScrMsgLine() {
return scrMsgLine;
}