6.6.5 Default mapping (unidirectional relationship)

A unidirectional relationship includes a Single-Valued relationship and a Multi-Valued relationship. The following points describe each relationship:

This subsection describes the default mapping of a unidirectional relationship.

Organization of this subsection
(1) Unidirectional Single-Valued relationship
(2) Unidirectional Multi-Valued relationship

(1) Unidirectional Single-Valued relationship

This section describes the default mapping of a unidirectional OneToOne relationship and a unidirectional ManyToOne relationship.

(a) Unidirectional OneToOne relationship

This section describes the default mapping of a unidirectional OneToOne relationship applied in the following conditions:

Conditions
  • Entity A references the stand-alone instance of entity B and sets @OneToOne (or the corresponding XML tags in the O/R mapping file).
  • Entity A is not referenced from entity B.
  • Entity A is the relationship owner.
Applied default mapping
  • Entity A is mapped to table A.
  • Entity B is mapped to table B.
  • Table A must have the external key for table B. The name of the external key string is as follows:
    Name of the external key string
    Name of the relationship property (or field) of entity A_ Name of the primary key string of table B
    Note Italics indicate a variable value.
The external key string has the same type as the primary key of table B and is a unique key constraint.

Figure 6-9 Default mapping in a unidirectional OneToOne relationship

[Figure]
(b) Unidirectional ManyToOne relationship

This section describes the default mapping of a unidirectional ManyToOne relationship applied in the following conditions:

Conditions
  • Entity A references the stand-alone instance of entity B and sets @ManyToOne (or the corresponding XML tags in the O/R mapping file).
  • Entity A is not referenced from entity B.
Applied default mapping
  • Entity A is mapped to table A.
  • Entity B is mapped to table B.
  • Table A must have the external key for table B. The name of the external key string is as follows:
    Name of the external key string
    Name of the relationship property (or field) of entity A_ Name of the primary key string of table B
    Note Italics indicate a variable value.
The external key string must have the same type as the primary key of table B.

Figure 6-10 Default mapping in a unidirectional ManyToOne relationship

[Figure]

(2) Unidirectional Multi-Valued relationship

This section describes the default mapping of a unidirectional OneToMany relationship and a unidirectional ManyToMany relationship.

(a) Unidirectional OneToMany relationship

This section describes the default mapping of a unidirectional OneToMany relationship applied in the following conditions:

Conditions
  • Entity A references the entity B collection. @OneToMany (or the corresponding XML tags in the O/R mapping file) is set in the collection.
  • Entity A is not referenced from entity B.
  • Entity A is the relationship owner.
Applied default mapping
  • Entity A is mapped to table A.
  • Entity B is mapped to table B.
  • Apart from table A and B, a junction table named A_B where the name of the owner table appears at the beginning, is necessary. This junction table has two external key strings.
    The first external key string references table A and has the same type as the primary key of table A. The name of this external key string is as follows:
    Name of the external key string
    Name of entity A_ Name of the primary key string of table A
    The other external key string references table B, has the same type as the external key of table B, and is a unique key constraint. The name of this external key string is as follows:
    Name of the external key string
    Name of the relationship property (or field) of entity A_ Name of the primary key string of table B
    Note Italics indicate a variable value.
    Note
    A unidirectional OneToMany relationship that uses a junction table as described in this example might not be supported with JPA Providers other than Cosminexus JPA Provider. Note this when you operate applications created with a unidirectional OneToMany relationship using JPA Providers other than Cosminexus JPA Provider.

Figure 6-11 Default mapping in a unidirectional OneToMany relationship

[Figure]

(b) Unidirectional ManyToMany relationship

This section describes the default mapping of a unidirectional ManyToMany relationship applied in the following conditions:

Conditions
  • Entity A references the entity B collection. @ManyToMany (or the corresponding XML tags in the O/R mapping file) is set in the collection.
  • Entity B does not reference entity A.
  • The owner is entity A.
Applied default mapping
  • Entity A is mapped to table A.
  • Entity B is mapped to table B.
  • Apart from table A and B, a junction table named A_B where the name of the owner table appears at the beginning, is necessary. This junction table has two external key strings.
    One of the external key strings references table A and has the same type as the external key of table A. The name of this external key string is as follows:
    Name of the external key string
    Name of entity A_Name of the primary key of table A
    The other external key string references table B and has the same type as the primary key of table B. The name of this external key string is as follows:
    Name of the external key string
    Name of the relationship property (or field) of entity A_ Name of the primary key of table B
    Note Italics indicate a variable value.

    Figure 6-12 Default mapping in a unidirectional ManyToMany relationship

    [Figure]