title: Hibernate: one-to-one lazy loading, optional = false
body: <p>I faced the problem that <strong>one-to-one lazy loading</strong> doesn't work in hibernate. I've <strong>already solved it</strong>, but still <strong>don't</strong> properly <strong>understand</strong> what happens. </p>
  
  <p>My code (<strong>lazy loading doesn't work here</strong>, when I pull Person - Address is also fetched):</p>
  
  <pre><code>@Entity
  public class Person{
  
    @Id
    @SequenceGenerator(name = "person_sequence", sequenceName = "sq_person")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "person_sequence")
    @Column(name = "id")
    private long personID;
  
    @OneToOne(mappedBy="person", cascade=CascadeType.ALL, fetch = FetchType.LAZY)
    private Adress address;
    //.. getters, setters
  }
  
  @Entity
  public class Address {
  
    @Id
    @Column(name="id", unique=true, nullable=false)
    @GeneratedValue(generator="gen")
    @GenericGenerator(name="gen", strategy="foreign", parameters=@Parameter(name="property", value="person"))
    private long personID;
  
    @PrimaryKeyJoinColumn
    @OneToOne
    private FileInfo person;
  }
  </code></pre>
  
  <p><strong>But</strong>: if I add <strong><code>optional=false</code></strong> in OneToOne relationship, lazy loading <strong>works fine</strong>!</p>
  
  <pre><code>@OneToOne(mappedBy="person", cascade=CascadeType.ALL, optional = false, fetch = FetchType.LAZY)
  private Adress address;
  </code></pre>
  
  <p><strong>Question/Entreaty:</strong> please, explain to me how <code>optional=false</code> annotation helps to achieve lazy loading.</p>
  
  <p><strong>P.S.</strong> I've read posts <a href="https://stackoverflow.com/questions/1444227/making-a-onetoone-relation-lazy">post1</a> and <a href="https://community.jboss.org/wiki/SomeExplanationsOnLazyLoadingone-to-one" rel="noreferrer">post2</a>, and understand why simple OneToOne can't be lazy, but I still can't grasp <code>optional=false</code> magic.</p>