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

Sharing is Caring

This post is about one basic question of Master-Detail relation between business components
How to delete child records on delete of parent record?

So the 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 view links are created automatically due to the foreign key relationships in the database



    • Here Departments is parent table and Employees is a 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 is 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 a class and required methods
      See Accessors and Remove Method will be created in this class


Delete child records


    • 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 in 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 of EntityObject class and Association accessors, in the same way, other operation can be performed as updating all child rows, the sum of a column of child records etc
Thanks, Happy Learning 🙂

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *