How to use Oracle Sequence Numbers in DBUnit?

旧时模样 提交于 2019-12-11 04:29:41

问题


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


回答1:


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"/>


来源:https://stackoverflow.com/questions/16697740/how-to-use-oracle-sequence-numbers-in-dbunit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!