2010年11月15日星期一

Composition Association in ADF BC

This post first illustrate how to model the one-to-many relationship in the ER model by ADF BC. After that, the many-to-many (the mapping was stored in a third table) relationship in the ER model’s implementation was demonstrated.

Association between entities has two different types of relation. The first one is references, which means the source entity refers the destination entity; without the source entity, the destination entity still exists.  The second one is the contains, which means the source entity contains the destination entity as a logical, nested part; without the source entity, the destination entity still exists.  The contains relation is a composite association.

JDeveloper will generate the composite association for an Association if the foreign key is set as ON DELETE CASCADE.  An entity object offers additional runtime behavior in the presence of composition. http://download.oracle.com/docs/cd/E15051_01/web.1111/b31974/bcentities.htm#sm0150

If there are more than one composition association for the same entity object, the other composition associations should be disabled, otherwise the program should provide additional composition management to the entity object.  The problem arises because when a composed entity is created, it performs an existence check on the value of the foreign key to ensure that it identifies an existing entity as its owning parent entity. If no foreign key is found, there will throw an InvalidOwnerException. 

I think only with composition association can a master-detail binding be implemented.  Actually dis-select the composition association in both associations will make both the master-details run properly. 

In a master-detail mapping, if the composition association is not enabled, the master record and its detail records cannot be inserted at the same transaction, since when insert the detail records, the details records have no foreign key reference (the current value of the id of the master record is not assigned by the DBSequence).

This means the composite association should only be used in the one-to-many mapping scenario. A single entity object can not be in two different composite associations.

In a many-to-many mapping with the mapping stored in the intersection table, the many-to-many can be decomposed into two one-to-many mappings, although NEITHER the two mappings should be set as the composite association.None should be set as the composite association.

Please reference http://liuwuhua.blogspot.com/2010/11/master-detail-crud-in-adf-bc.html for an example.