Product Information > JADE Error Messages and System Messages > 2 through 1299 - JADE Object Manager Errors > 1272 - Attempt to add duplicate element to array with inverse

1272   Attempt to add duplicate element to array with inverse

Cause

This error occurs if JADE encounters a duplicate entry in an array that participates in an inverse relationship. An example of this error is as follows.

  1. There are two classes: Department and Employee.

  2. Each Department has an array collection, allEmployees, of all of its employees.

  3. Each Employee has a reference, myDept, to their department.

  4. An inverse reference is defined between myDept and allEmployees, so that one department has many employees and a single employee has only one department. The allEmployees property is defined with an update mode of manual.

  5. An instance of Employee, e, is created.

  6. An instance of Department, d, is created.

  7. e is added to d.allEmployees with d.allEmployees.add(e), which automatically sets e.myDept to d.

  8. e is again added to d.allEmployees with d.allEmployees.add(e), at which point JADE attempts to automatically update e.myDept.

  9. This causes a 1272 - Attempt to add duplicate element to array with inverse error, as in attempting to update e.myDept to d, JADE finds that d is already referenced by e.myDept. This is disallowed, because if it were allowed and later one of the references to e was removed from the array d.allEmployees, the reference from e.myDept to d would be automatically removed even though there was still a copy of e in the array.

Note that having duplicates in an array is not an error if there is no inverse relationship.

Action

Change your application code to avoid a duplicate entry in an array that participates in an inverse relationship.

With respect to the above example, you should consider the following coding changes.