How to use Oracle Sequence Numbers in DBUnit?
Asked Answered
A

1

1

How can I used Oracle Sequences to auto-generate primary keys for my tables while exporting data into Oracle using DBUnit ?

Azikiwe answered 22/5, 2013 at 17:9 Comment(1)
Take a look at this. It seems a potential solution although not out-of-box.Bonner
J
3

I had the same issue and didn't find any answer. I ended up using a trigger to automatically generate the technical key, as described in this post create 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 simply ommit the id column in the initial and expected datasets:

<ticket title="Ticket 1"
        description="Description for ticket 1"
        status="NEW"
        created_date="2013-07-01 12:00:00"/>
Jolt answered 27/8, 2013 at 8:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.