Friday 17 June 2016

Code for finding the Entity or Rows by using the Primary Key in ADF

Use the below process/code to find the Entity instance based on the primary key.
  1. Get the EntityDefinition object by using the EntityImpl class.
  2. Use createPrimaryKey() method available in the EntityImpl to create the key.
  3. Use the EntityDefImpl object findyByPrimaryKey method and pass the key you created in the previous step.
  4. The findByPrimaryKey method gives the EntityImpl, which is an representation of row.

 In this example we are considering the EmployeeEO and empId as primary key.
Private EmployeeEOImpl findEmpById(String empId){
EntityDefImpl empDef= EmployeeEOImpl.getDefinitionObject();//Finding the Defintion
Key empKey= EmployeeEOImpl.createPrimaryKey(new Integer(empId));//Creating the Key
Return (EmployeeEOImpl) empDef.findByPrimaryKey(getDBTransaction(),empKey);
}


No comments:

Post a Comment