title: Spring JPA Lazy loading @OneToOne entities doesn't work
body: <p>I'm having trouble making <code>OrderEntity</code> object load <code>BillingAddress</code> lazily. I've seen questions revolving around this asked a lot and followed instructions, including adding optional = false but <code>BillingAddress</code> still gets loaded whenever I <code>findById</code> an <code>OrderEntity</code>.</p>
  <p>These are my entities (reduced for the sake of this question):</p>
  <p><strong>OrderEntity</strong></p>
  <pre><code>@Entity
  @Table(name = &quot;orders&quot;, schema = &quot;glamitoms&quot;)
  public class OrderEntity {
  
      @Id
      @Column(name = &quot;id&quot;)
      private int id;
  
      @OneToOne(mappedBy = &quot;order&quot;, cascade = CascadeType.ALL, fetch = FetchType.LAZY, optional = false)
      private BillingAddressEntity billingAddress;
  
  }
  </code></pre>
  <p><strong>BillingAddressEntity</strong></p>
  <pre><code>@Entity
  @Table(name = &quot;billing_address&quot;, schema = &quot;glamitoms&quot;)
  public class BillingAddressEntity {
  
      @Id
      @Column(name = &quot;order_id&quot;)
      private int id;
  
      @OneToOne(fetch = FetchType.LAZY)
      @MapsId
      private OrderEntity order;
  }
  </code></pre>
  <p><strong>TestController</strong></p>
  <pre><code>@RestController
  public class TestController {
  
      private OrdersDAO ordersDAO;
  
      @Autowired
      public TestController(OrdersDAO ordersDAO) {
          this.ordersDAO = ordersDAO;
      }
  
      @GetMapping(&quot;/test&quot;)
      public void test() {
          OrderEntity orderEntity = ordersDAO.findById(1).get();
      }
  }
  </code></pre>
  <p><strong>OrdersDAO</strong></p>
  <pre><code>@Repository
  public interface OrdersDAO extends JpaRepository&lt;OrderEntity, Integer&gt; {
  }
  </code></pre>
  <p>The table <code>billing_address</code> has a FK referencing orders. I've read contradicting answers saying adding <code>optional = false</code> should load entities lazily, but for me, that doesn't seem to work. Am I missing something in any of these entities?</p>