Hitachi

uCosminexus Application Server Compatibility Guide


9.6.2 Annotations for relationships

The entities handle the relation between tables as a relationship. When you handle a relationship with an entity, the reference to another entity is stored as a field in the entity. In addition, set the following relationship annotations in the persistence property or instance variable that references an entity:

The following figure shows the relationship between entities and the relation between tables.

Figure 9‒5: Relationship between entities and relation between tables

[Figure]

If the relationship annotation is not specified for referencing the entity, the operations will not function properly. Note that if the generic type is not used in the reference where collection is used, the target entity must be specified as the relationship target.

Instead of using an annotation, you can also define a relationship using the O/R mapping file. However, note that when a relationship is defined in the O/R mapping file and if the same definition is specified in the annotation, the definition in the annotation is overwritten.

Default mapping in the relationship annotations

When the annotations for the OneToOne, OneToMany, ManyToOne, and ManyToMany relationships are applied, the default mapping rules are applied. Similarly when a relationship is specified in the O/R mapping file, the default mapping is applied.

When you use the default mapping of the relationship annotations, if the database tables and relations differ from the default values specified in 9.6.4 Default mapping (bi-directional relationship) or 9.6.5 Default mapping (unidirectional relationship), the SQL statement cannot be created correctly in the database query during execution. An exception occurs.