How to use Oracle sequence numbers in DBUnit?

How can I use Oracle Sequences to automatically generate primary keys for my tables when exporting data to Oracle using DBUnit?

+1
source share
1 answer

I had the same problem and there was no answer. I ended up using a trigger to automatically create a technical key, as described in this article create a table with sequence.nextval in oracle

CREATE OR REPLACE TRIGGER ticketSequenceTrigger
BEFORE INSERT
ON TICKET
FOR EACH ROW
WHEN (new.id IS null)
  DECLARE
    v_id TICKET.id%TYPE;
  BEGIN
    SELECT TICKET_ID_SEQ.nextval INTO v_id FROM DUAL;
    :new.id := v_id;
  END ticketSequenceTrigger;

Then I just omit the id column in the source and expected datasets:

<ticket title="Ticket 1"
        description="Description for ticket 1"
        status="NEW"
        created_date="2013-07-01 12:00:00"/>
+2
source

All Articles