Hibernate @OneToOne @NotNull
- by Marty Pitt
Is it valid to declare @OneToOne and @NotNull on both sides of a relationship, such as:
class ChangeEntry
{
@OneToOne(cascade=CascadeType.ALL)
@NotNull
ChangeEntryDetails changeEntryDetails;
}
class ChangeEntryDetails
{
@OneToOne(cascase=CascadeType.ALL)
@NotNull
ChangeEntry changeEntry;
}
I can't find anything that says this is invalid, but it seems that during persistence at least one side of the relationship must be violated. (Eg., if writing changeEntry first, changeEntryDetails will be null temporarily).
When trying this, I see an exception thrown not-null property references a null or transient value.
I'd like to avoid relaxing the constraint if possible, because both sides must be present.