Saturday, 27 July 2013

Set DB Sequence number as default value to entity object

In this post i will explain you about setting default value to entity object.
It is very common requirement, where you need to set DB sequence number to entity object. I am using Employees table and Employees_seq (sequence) in this example.

There are two ways of setting default value
1. Groovy Expression    2. Entity Object Java class

1. Groovy Expression
Create the Employees entity object and go to attributes tab in that select employee_id and then go to the default value and select the expression paste the below expression in the text box.

(new oracle.jbo.server.SequenceImpl("EMPLOYEES_SEQ",adf.object.getDBTransaction()))

2. Entity Object java class

Create the entity object java class and include the create method in that. Then use the below code in create  method.

        SequenceImpl seq=new SequenceImpl("EMPLOYEES_SEQ",getDBTransaction());

Final step is to create Employee view and Application module, run your AM, You vill see the result when ever u add new record.


  1. HI Nitish.. Thank You for the useful info. Can you please let me know , how to create tables from existing Entity Objects (.xml files) in ADF (Using JDeveloper)

    1. Hi Shiva,
      Here is the post to create DB tables from entity object


  2. Hi,

    I copy pasted the below expression
    (new oracle.jbo.server.SequenceImpl("EMPLOYEES_SEQ",adf.object.getDBTransaction()))

    but still am getting an error like

    "(oracle.jbo.domain.DataCreationException) JBO-25009: Cannot create an object of type:oracle.jbo.domain.Number from type:java.lang.String with value:(new oracle.jbo.server.SequenceImpl("EMPLOYEES_SEQ",adf.object.getDBTransaction())).getSequenceNumber()"