Sunday, January 16, 2011

Composition Associations



A composition association represents a relationship between entities, such as an entity A (eg: DepartmentEO) referenced by an entity B(eg:EmployeeEO) or a entity C(eg:BonusEO) contained in an entity B(eg:EmployeeEO). When you create composition associations, it is useful to know about the kinds of relationships you can represent, and the various options.

Associations between entity objects can represent two styles of relationships depending on whether the source entity:

* References the destination entity
* Contains the destination entity as a logical, nested part

For example, an EmployeeEO entry references a DepartmentEO. This relationship represents the first kind of association, reflecting that a DepartmentEO or an EmployeeEO entity object can exist independent from each other. In addition, the removal of an Employee does not imply the cascade removal of the Department to which it was referring.

In contrast, the relationship between EmployeeEO and its collection of related BonusEO details is stronger than a simple reference. The BonusEO entries comprise a logical part of the overall EmployeeEO. In other words, a EmployeeEO is composed of BonusEO entries. It does not make sense for a BonusEO entity row to exist independently from an EmployeeEO, and when an EmployeeEO is removed — assuming the removal is allowed — all of its composed parts should be removed as well. This kind of logical containership represents the second kind of association, called a composition association.

No comments: