Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Unable to insert a new row with a sequence generated column id

rathnamDec 8 2011 — edited Dec 8 2011
Hi,

I am trying to insert a new row into a table containing a db sequence based column used as primary key.

Below is the code from custom method in the corresponding AM I am using to insert the new row:

Row row2 = getCaAppointments1().createRow();
row2.setAttribute("MemberId", memberId);
row2.setAttribute("Status", "Planned");
row2.setAttribute("CreatedBy", coachId);
row2.setAttribute("CreationDate", date);
//AppointmentId will be generated by the sequence
DBSequence newId = (DBSequence) row2.getAttribute("AppointmentId");
//SequenceImpl s = new SequenceImpl("XX_CA_APPOINTMENT_ID", getDBTransaction());
//Long next = newId.getSequenceNumber().longValue();
System.out.println("Got sequence id as: " + newId);
row2.setAttribute("AppointmentId", newId);
row2.setAttribute("CoachId", coachId);
row2.setAttribute("Type", "0");
row2.setAttribute("AppointmentNumber", 0);
row2.setAttribute("PlannedDate", doj);
getCaAppointments1().insertRow(row2);

I have set the EO attribute "AppointmentId" to use a DBSequence. I tried out different combinations to get the Sequence Id and insert a row. Nothing worked well and I am unable to insert a new row.

If I avoid setting the "AppointmentId" attribute and try to insert a row, it fails with below error:

ORA-01400: cannot insert NULL into ("APPS"."XX_CA_APPOINTMENTS"."APPOINTMENT_ID") ORA-06512: at line 1

Tried inserting new row using BCTester but I am hitting the same error there (I was unable to modify the "AppointmentId" column value while inserting the row since that column was read only and it was showing value as -2).

I assume that since the column/attribute is already marked to use a DBSequence, the value should be assigned by default and I should not hit "Cannot Insert NULL value to that column".
Am I missing some thing required to trigger the sequence to automatically generate new Id and assign it to new row before it getting created ??

Please let me know the fix.

Thanks in advance
Rathnam
This post has been answered by Rem oved on Dec 8 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 5 2012
Added on Dec 8 2011
6 comments
1,968 views