Jdeveloper ADF  sequence implementations scenarios for PK assignment   Dec, 2008

1) if there is no associations, and you do not need to show the PK on the UI, you may settle for a database trigger that assigns  nextval for the PK  (database solution)

2) You can use the DBSequence domain for the PK attribute.  This will assign a negative unique no to the field, the usage of DBSequence doamin automatically checks the Refresh after Insert property.  Then a database trigger needs to be written that assigns nextval for the PK.  In this case, when the create() method is called, the negative no is created and when the transaction is committed, the database trigger fires and the correct sequence no is generated.

3) Another method would be to not to use database trigger and write some code that shall fetch the next sequence

        protected void create() {

            super.create(attributeList);

           DBTransaction trans = getDBTransaction();

           SequenceImp seq =  new SequenceImp ("sequence_name",trans); //sequence_name is a database sequence

           setID(seq.getSequenceNumber());

}

 

a typical database trigger to implement sequence no

 

first create a database sequence

 

SQL> Create sequence my_seq;

 

SQL> Create database trigger getSeq

        before insert on myemp

       for each row

       begin

           SELECT my_seq.nextval

                      into :new.id

           FROM  dual;

end ;