I have few columns in table Journal of which JournalKey is Primary key and JournalID has Unique Constraint.
JournalKey is autogenerated Key.
Now when i start saving using insertOrUpdate, i have expected hibernate to Insert the row when JournalID is not present else update it.
Since JournalKey is autogenerated it doesn't have much role to play. However it gives me UniqueConstraintViolation error.
Kindly help.
Journal is save as
public Object saveOrUpdateObj(Object obj){
Session session = HibernateUtil.getSession();
try{
session.beginTransaction();
session.saveOrUpdate(obj);
session.getTransaction().commit();
}finally{
session.close();
}
return obj;
}
Journal class is defined this way
@Entity
@Table(name="Dim_Journal")
public class Journal {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="JournalKey")
private Long journalKey;
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name="FK_Org_Key")
private Organisation organisation;
@Column(name="JournalID")
private String journalID;
@Column(name="JournalDate")
private Date journalDate;
@Column(name="JournalNumber")
private String JournalNumber;
@Column(name="JournalCreationDate")
private Date createdDateUTC;
@Column(name="SourceID")
private String SourceID;
@Column(name="SourceType")
@Enumerated(EnumType.STRING)
private JournalSourceType sourceType;
@Transient
private List<JournalLine> journalLines;
@Transient
private Long organisationId;
}