title: Hibernate @OneToOne @NotNull
body: <p>Is it valid to declare <code>@OneToOne</code> and <code>@NotNull</code> on both sides of a relationship, such as:</p>
  
  <pre><code>class ChangeEntry
  {
      @OneToOne(cascade=CascadeType.ALL)
      @NotNull
      ChangeEntryDetails changeEntryDetails;
  
      public void addDetails(ChangeEntryDetails details) {
         this.changeEntryDetails = details;
         details.setChangeEntry(this);
      }
   }
  
   class ChangeEntryDetails
   {
       @OneToOne(cascase=CascadeType.ALL)
       @NotNull
       ChangeEntry changeEntry;
  
       public void setChangeEntry(ChangeEntry changeEntry)
       {
            this.changeEntry = changeEntry;
       }
   }
  </code></pre>
  
  <p>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).</p>
  
  <p>When trying this, I see an exception thrown <code>not-null property references a null or transient value</code>.</p>
  
  <p>I'd like to avoid relaxing the constraint if possible, because both sides <strong>must</strong> be present.</p>