Hibernate @OneToOne @NotNull

Posted by Marty Pitt on Stack Overflow See other posts from Stack Overflow or by Marty Pitt
Published on 2010-04-27T21:01:02Z Indexed on 2010/04/27 21:03 UTC
Read the original article Hit count: 423

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about hibernate

Related posts about java