Follow by Email

Monday, 5 January 2015

ADF Basics: Delete child records on delete of parent record, Overriding remove() in EntityObject class

This post is about one basic question of Master-Detail relation between business components
How to delete all child records on delete of parent record ?
So answer is quite simple , see the steps how to achieve this?

  • Create a Fusion Web Application and prepare model project using Departments and Employees table of HRSchema.
    you can see multiple associations and viewLinks are created automatically due to foreign key relation in database

  • Here Departments is parent table and Employees is child, so there is an association between both entity objects , open this association and goto Association Properties . Now you can see source and destination accessor name that are created in both entity objects

  • Next step is to create EntityObject java class. To do this open Departments entity object -- go to java section-- click on edit icon and check the box to create class and required methods
    See Accessors and Remove Method will be created in this class

  • Open DepartmentsEOImpl class and check there is a method that returns RowIterator of Employees (this is Accessor)

  •     /**
         * @return the associated entity oracle.jbo.RowIterator.
        public RowIterator getEmployeesEO1() {
            return (RowIterator)getAttributeInternal(EMPLOYEESEO1);

  • Now locate remove method in EOImpl, this method is called every time when delete operation for Departments is executed so add this code to remove(); method

  •     /**
         * Add entity remove logic in this method.
        public void remove() {
            //Get all Employees of currenlty selected Department
            RowIterator employees = getEmployeesEO1();
            while (employees.hasNext()) {
                //Delete all Employees
            //Delete Department itself after deleting all Employees associated with it

This is how we can make use EntityObject class and Association accessors, in the same way other operation can be performed as updating all child rows, sum of a column of child records etc
Thnaks , Happy Learning :)

No comments :

Post a Comment