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.