If you are using Oracle. Just make a Sequence object and a Trigger
object that fires on insert to your main table. In the trigger it gets
the next value of the sequence and uses that to insert into the table.
create or replace TRIGGER
"YOURSCHEMA"."YOURTABLE_YOURTABLEID_TRG" BEFORE INSERT OR UPDATE ON
YOURTABLE
FOR EACH ROW
DECLARE
v_newVal NUMBER(12) := 0;
v_incval NUMBER(12) := 0;
BEGIN
IF INSERTING AND :new.YourTableID IS NULL THEN
SELECT YourSequenceTriggerID_SEQ.NEXTVAL INTO v_newVal FROM DUAL;
-- If this is the first time this table have been inserted into
(sequence == 1)
IF v_newVal = 1 THEN
--get the max indentity value from the table
SELECT max(YourTableID) INTO v_newVal FROM YourTable;
v_newVal := v_newVal + 1;
--set the sequence to that value
LOOP
EXIT WHEN v_incval>=v_newVal;
SELECT FYourSequenceTriggerID_SEQ.nextval INTO v_incval FROM
dual;
END LOOP;
END IF;
-- assign the value from the sequence to emulate the identity column
:new.FacilityID := v_newVal;
END IF;
END;