Annotation Interface OneToOne
Specifies a one-to-one relationship between two entities.
This annotation is used to configure the mapping between the owning side and the inverse side of the relationship.
Example usage:
@Entity
public class EntityA {
@OneToOne(mappedBy = "entityA", cascade = CascadeType.DELETE, fetch = FetchType.LAZY)
private EntityB entityB;
// Other fields and methods
}
@Entity
public class EntityB {
// No need to specify mappedBy when the relationship is unidirectional
@OneToOne(cascade = CascadeType.DELETE, fetch = FetchType.LAZY)
private EntityA entityA;
// Other fields and methods
}
-
Optional Element Summary
-
Element Details
-
mappedBy
String mappedByThe name of the field in the inverse side of the relationship. This is required unless the relationship is unidirectional. Defaults to an empty string, indicating that the relationship is not mapped by another field.- Default:
""
-
cascade
CascadeType[] cascadeDefines the cascade behavior for the relationship. By default, no cascading behavior is applied.- Default:
{}
-
fetch
FetchType fetchDefines the fetching strategy used to load the related entity. By default, eager fetching is used.- Default:
EAGER
-