title: How to delete only one side of @OneToOne bi-directional mapping in hibernate
body: <p>I have two columns in two separate entities</p>
  
  <blockquote>
    <p>Interview entity</p>
  </blockquote>
  
  <pre><code>@OneToOne(cascade=CascadeType.PERSIST, orphanRemoval = true)
  @JoinColumn(name = "applicant_id", nullable=false)
  private Applicant applicant_id;
  </code></pre>
  
  <blockquote>
    <p>Applicant entity</p>
  </blockquote>
  
  <pre><code>@OneToOne(mappedBy="applicant_id", cascade = CascadeType.ALL, orphanRemoval = true)
  private Interview interview_id;
  </code></pre>
  
  <p><strong>Question is, how do I map this correctly so that I can run <code>service.deleteInterview();</code> and delete only <code>interview</code> entity record?</strong> </p>
  
  <p>If I use <code>cascadeType.all</code> that removes the <code>applicant</code> entity. I tried changing this to persist then I get a 500 error saying that the entity will be recreated if the function is called.</p>
  
  <p>Adding <code>orphan removal=true</code> ended up with this exception <code>org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null];</code></p>
  
  <p>I was thinking of assigning <code>mappedBy</code> to <code>interview</code> entity, however, I am not sure if that would be the solution and also I have reservations as my <code>interview</code> entity is created after the creation of an <code>applicant</code> entity.</p>