-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Issue with Composite Key and AutoGen Seq
PostPosted: Tue Feb 25, 2014 12:33 am 
Newbie

Joined: Wed Feb 12, 2014 8:24 pm
Posts: 3
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")


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.