Friday, 2 August 2013

ADF has multiple ways to implement sequences for primary key,In this tutorial we will see how we can use DB Sequence and DB Trigger to set unique sequence for an attribute .The reason why we prefer this approach is ,the sequence does not loose a number  if user chooses to cancel or close the transaction.


First of all create a sequence (DEMO_SEQUENCE )  in your database . 



Now use the DEMO_SEQUENCE sequence to create a trigger that retrieves the latest sequence .























Select the sequence name and column name to apply the trigger


















A trigger will get created in DB 




Open the EmployeeDetailsView entity and open the attributes tab , edit the employeeId attribute .
change the attribute type to 'Dbsequence' .Mark the attribute updatable -'Never'





Now we are almost done, open the select the appmodule and run.                                                                








Now insert a new row in employee view to insert a new record ,click in the '+' icon 




















Look in the picture the initial value assigned to employee Id is '-2' , , Once we fill all the record and commit ,the trigger executes and it will populate the actual value of employee id from sequence.
















Thanks!!!

0 comments:

Post a Comment