title: Saving an entity with one-to-one relation in JPA
body: <p>I have an entity <code>Request</code>:</p>
  <pre><code>@Entity
  public class Request {
  
      @Id
      @GeneratedValue
      private Long id;
  
      @OneToOne
      private Candidate candidate;
  
      ...
  }
  
  </code></pre>
  <p>To create and save above entity into JPA repository, I will be doing something like following:</p>
  <pre><code>Candidate candidate = candidateRepository.findById(requestUpdate.getCandidate()).orElse(null);
  
  Request request = new Request(candidate);
  Request save = requestRepository.save(request);
  </code></pre>
  <p>As <code>Request</code> table in DB stores FK for candidate, I think it should be enough to set an id. But JPA expects me to set candidate object. This forces me to query candidate repository.</p>
  <p>Is it necessary to query for candidate from candidate repository to save <code>Request</code>
  or
  If I have candidate id available, can't I set it directly ?</p>