Friday, September 3, 2010

Auto Generated Key in Entity Object

Here by this post I am sharing information about how to set auto generate key for entity object.


Below are the steps:

  • Create a Fusion Web Application.
Select the model project and perform following steps:
  • Create a Business Components from Table, Select Employees table for Entity Object.
  • Create the view updatable view object for Employees View Object.
  • Create Read only view for Department and Jobs.
  • Define list of values for Manager Id, Job and Department Id in Employees View.
  • In Employees View Object set the EmployeeId updatable to never.
  • Open the Employee view object into editor, Select the Java Option then click on the edit button.

  • Select the above option on Java Option popup. It will generate the EntityImpl class for Employees Entity With the selected methods.
  • Open the EmployeesImpl.java file --> goto the create methods.
Edit that method with following code
    /**
     * Add attribute defaulting logic in this method.
     * @param attributeList list of attribute names/values 
     * to initialize the row
     */
    protected void create(AttributeList attributeList) {
        super.create(attributeList);
        SequenceImpl seqImpl = new SequenceImpl("EMPLOYEES_SEQ",
                  getDBTransaction());
        Number num = seqImpl.getSequenceNumber();
        setEmployeeId(num);
    }

Now select the ViewController project and perform following steps:
  • Create a jspx page.
  • Drag and drop view object and create ADF form and table.
  • Drag and drop all the operation like Create Insert, Commit and Rollback to page for creating record, saving it to database.
  • Final steps to run your application. 
  • Once you click on the Create Insert button form will appear blank with new employee id. 

  • Enter data and save it to database.

You can find running workspace from AutoGeneratedKeyForEOSample.zip