Given a set of requirements and entity classes choose and implement an appropriate object-relational mapping for association relationships.


Relationships among entities may be one-to-one, one-to-many, many-to-one, or many-to-many. Relationships are polymorphic.

If there is an association between two entities, one of the following relationship modeling annotations MUST be applied to the corresponding persistent property or instance variable of the referencing entity: OneToOne, OneToMany, ManyToOne, ManyToMany. For associations that do not specify the target type (e.g., where Java generic types are not used for collections), it is necessary to specify the entity that is the target of the relationship.

Relationships may be bidirectional or unidirectional. A bidirectional relationship has BOTH an owning side and an inverse side. A unidirectional relationship has ONLY an owning side. The owning side of a relationship DETERMINES the updates to the relationship in the database.

The following rules apply to bidirectional relationships:

The relationship modeling annotation constrains the use of the cascade=REMOVE specification. The cascade=REMOVE specification should ONLY be applied to associations that are specified as OneToOne or OneToMany. Applications that apply cascade=REMOVE to other associations are not portable.

Note that it is the application that bears responsibility for maintaining the consistency of runtime relationships - for example, for insuring that the "one" and the "many" sides of a bidirectional relationship are consistent with one another when the application updates the relationship at runtime.

If there are no associated entities for a multi-valued relationship of an entity fetched from the database, the persistence provider is responsible for returning an EMPTY COLLECTION as the value of the relationship.

Professional hosting     Belorussian informational portal         Free SCWCD 1.4 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     Free IBM Certified Associate Developer Study Guide     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide     Free Mock Exam Engine