@Retention(CLASS) @Target({FIELD})

public @interface OneToOne

Maps a single related entity with a unique owning foreign key, or an inverse mappedBy field.

Methods

public abstract FetchType fetch() default FetchType.EAGERControls relationship initialization.
public abstract CascadeType[] cascade() default {}Chooses operations to propagate to related entities.
public abstract String mappedBy() default ""Names the owning Java relationship field on the target entity.
public abstract boolean orphanRemoval() default falseDeletes a related entity removed from this one-to-one or one-to-many association at flush.
public abstract boolean optional() default trueAllows an owning to-one relationship to be null.

Method details

fetch

public abstract FetchType fetch() default FetchType.EAGER
Controls relationship initialization.

Returns

fetch policy; EAGER for to-one and LAZY for collections by default

cascade

public abstract CascadeType[] cascade() default {}
Chooses operations to propagate to related entities.

Returns

cascade operations; empty by default

mappedBy

public abstract String mappedBy() default ""
Names the owning Java relationship field on the target entity.

Returns

owning field name, or empty for the owning side

orphanRemoval

public abstract boolean orphanRemoval() default false
Deletes a related entity removed from this one-to-one or one-to-many association at flush.

Returns

true to delete orphans; false by default

optional

public abstract boolean optional() default true
Allows an owning to-one relationship to be null.

Returns

true by default; false makes the generated foreign key required