• Online Training

    Online Training

    Generating Sequence Number for PrimaryKey in ADF

    It can be done in many ways using programatic  and declarative way. Let us see some of  the ways to generate DB Sequence for PK.

    1.Override the Create Method in EmployeesEOImpl class as follows:
    public void create(AttributeList attributeList) {
     //this is the code
         SequenceImpl seq = new SequenceImpl("EMP_SEQUENCE", getDBTransaction());
         Number seqNextval = seq.getSequenceNumber();
    2.Overriding initDefaults() in StudentEOImpl class as follows:
        protected void initDefaults() {
               SequenceImpl seq = new SequenceImpl("STUDENT_BASIC_INFO_SEQ", getDBTransaction());

    Note: If  u didn’t get how to go in to the initDefaults() or Create() methods ,go to source menu in the menu-bar --à override methods & select the above methods

    3.Declarative way :
    Go to Employee attribute section & double click on EmpId .
    Edit Attribute dialog will appear, Select value type is expression. In the value Field write the below expression
    (new oracle.jbo.server.SequenceImpl("EMP_SEQUENCE",adf.object.getDBTransaction()))
    4.Declarative way using Trigger:
    Trigger helps to retain the sequence even after rollback operation is done .
    Generate a Trigger on your table as below


    In the entity attribute section for DeptID , select below properties
    Refresh After=Update



    Post a Comment