9.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:
-
Unidirectional Single-Valued relationship
A unidirectional Single-Valued relationship is a relationship that references the stand-alone instance and where only the owner exists.
Possible unidirectional Single-Valued relationships are unidirectional OneToOne relationships and unidirectional ManyToOne relationships.
-
Unidirectional Multi-Valued relationship
A unidirectional Multi-Valued relationship is a relationship that references the entity in the collection format and where only the owner exists.
Possible unidirectional Multi-Valued relationships are unidirectional OneToMany relationships and unidirectional ManyToMany relationships.
This section describes the default mapping of a unidirectional relationship.
- Organization of this subsection
(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 9‒9: Default mapping in a unidirectional OneToOne relationship -
(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 9‒10: Default mapping in a unidirectional ManyToOne relationship -
(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.
- Important 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.
-
(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 9‒12: Default mapping in a unidirectional ManyToMany relationship
-