Hi I have a composite key - for the composite key I want the seq num to be auto generated if the value is null. at the moment hibernate insert the value as null. if I change the seq from Long to long - it then tries and inserts 0 which I dont want.
Any ideas?
Code:
@Embeddable
public class OrgReferenceSeqPk extends OrgReferencePk implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name = "C3_CPH_ORGANISATN", length = 5)
private String organisation = "";
@Column(name = "C3_CPH_REF_NUMBER", length = 30)
private String referenceNumber = "";
@Column(name = "SEQNUM" )
@GenericGenerator(name="increment", strategy = "increment")
@GeneratedValue(generator="increment")
private Long sequenceNumber;
}
Code:
@Entity
@Table(name = "PSCRIS.PS_C3_CPH_SUBJ")
public class Subject implements Serializable {
@Id
private OrgReferenceSeqPk orgReferenceSeqPk = new OrgReferenceSeqPk();
}
Code:
Subject subject = new Subject();
subject.setOrganisation("ABC");
subject.setReferenceNumber("123");
...
session.saveOrUpdate(subject);
--> error - ERROR: ORA-01400: cannot insert NULL into ("PSCRIS"."PS_C3_CPH_SUBJ"."SEQNUM")