2.7.37 @OneToOne

Organization of this subsection
(1) Description
(2) Element

(1) Description

This annotation indicates that the specified class has OneToOne relationship, and also specifies the single relationship between entity classes.

Furthermore, to achieve a bi-directional relationship, always specify the mappedBy element at the non--owner side.

The applicable targets are method and field.

(2) Element

The following table lists the elements of @OneToOne:

Element nameOptional/RequiredElement description
targetEntityOptionalThis element specifies the non--owner entity class.
cascadeOptionalThis element specifies the operations to be cascaded.
fetchOptionalThis element specifies the specification value of the fetch strategy.
optionalOptionalThis element specifies whether or not a null value can be set up for all non-primitive type fields and properties.
mappedByOptionalThis element specifies the name of the field that maintains a relationship in the owner entity class, when added in the elements of the non-owner entity class.

The details of attributes that are supported with Cosminexus JPA provider are as follows:

(a) targetEntity element
Type
Class
Description
This element specifies the non--owner entity class.
Default value
Type of the field and property in which the annotation is added
(b) cascade element
Type
CascadeType[]
Description
This element specifies the operations to be cascaded.
The following table describes the specifiable values:
  • CascadeType.ALL: The persist, remove, merge, and refresh operations of the owner entity class are cascaded to the related destination.
  • CascadeType.MERGE: The merge operation of the owner entity class is cascaded to the related destination.
  • CascadeType.PERSIST: The persist operation of the owner entity class is cascaded to the related destination.
  • CascadeType.REFRESH: The refresh operation of the owner entity class is cascaded to the related destination.
  • CascadeType.REMOVE: The remove operation of the owner entity class is cascaded to the related destination.
Default value
Not to be cascaded
(c) fetch element
Type
FetchType
Description
This attribute defines the fetch strategy of data from the database. For details on the fetch strategy, see 6.4.5 Synchronization with the database in the uCosminexus Application Server Common Container Functionality Guide.
The following two types of values can be specified:
  • EAGER strategy: Requests in which the data must be fetched eagerly
  • LAZY strategy: Requests in which data is fetched lazily when accessed for the first time
Default value
FetchType.EAGER
(d) optional element
Type
boolean
Description
This element specifies whether or not a null value can be set up for all non-primitive type fields and properties. The following values can be specified:
  • true: A null value can be set up for all non-primitive type fields and properties.
  • false: A null value cannot be specified for all non-primitive type fields and properties.
Default value
true
(e) mappedBy element
Type
String
Description
This element specifies the name of the field that maintains a relationship in the owner entity class, when added in the elements of the non-owner entity class. When this element is specified, the relationship becomes bi-directional.
Default value
None