title: When asked to load a lazy field, Hibernate loads all lazy fields
body: <p>I have a one2one relation between <code>Student</code> and <code>Address</code>. I want the <code>firstName</code> and <code>lastName</code> fields of <code>Student</code> to be lazy loaded. Also I want lazy for the <code>address</code> field.</p>
  
  <p>These are my entity classes:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Entity
  @Table(name = "students")
  public class Student {
  
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
  
    @OneToOne(mappedBy = "student", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @LazyToOne(LazyToOneOption.NO_PROXY)
    private Address address;
  
    @Basic(fetch = FetchType.LAZY)
    @Column(name = "first_name")
    private String firstName;
  
    @Basic(fetch = FetchType.LAZY)
    @Column(name = "last_name")
    private String lastName;
  
    // getters and setters
  }
  </code></pre>
  
  <p>The Address class:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Entity
  @Table(name = "addresses")
  public class Address {
  
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
  
    @OneToOne
    @JoinColumn(name = "s_id")
    private Student student;
  
    @Column
    private String street;
  
    // getters and setters
  }
  </code></pre>
  
  <p>My test method looks like this ( the Java 8 lambda is just creating an entitymanager in back and executes all in transaction ):</p>
  
  <pre class="lang-java prettyprint-override"><code>@Test
  public void dummyTest() {
    JPA_UTILS.runInTransaction(e -&gt; {
      Student s = e.find(Student.class, 150L);
      System.out.println("----------++++++++++++++-----------");
      s.getFirstName();
      System.out.println("----------++++++++++++++-----------");
    });
  }
  </code></pre>
  
  <p>So here I am loading an existing student from the database, then fetch the lazy property <code>firstName</code> (mapped to the <code>first_name</code> column). The problem is that Hibernate doesn't load only <code>firstName</code> but also <code>lastName</code> and <code>address</code> fields:</p>
  
  <pre><code>just.hibernate.one2one.TestApp &gt; dummyTest STANDARD_OUT
    Hibernate: 
      select
        student0_.id as id1_1_0_ 
      from students student0_ 
      where student0_.id=?
    ----------++++++++++++++-----------
    Hibernate: 
       /* sequential select just.hibernate.one2one.Student */
      select
        student_.first_name as first_na2_1_,
        student_.last_name as last_nam3_1_ 
      from students student_ 
      where student_.id=?
    Hibernate: 
      /* load just.hibernate.one2one.Address */
      select
        address0_.id as id1_0_1_,
        address0_.street as street2_0_1_,
        address0_.s_id as s_id3_0_1_,
        student1_.id as id1_1_0_ 
      from addresses address0_ 
      left outer join students student1_  on address0_.s_id=student1_.id 
      where address0_.s_id=?
    ----------++++++++++++++-----------
  </code></pre>
  
  <p>I don't want this behavior, I want to load only what I request. Can someone help me find the problem ?</p>
  
  <p>Thanks</p>
  
  <p>UPDATE1:</p>
  
  <p>Instrumentation is done with maven, I'm posting only the relevant code (I've tried with gradle and the same results)</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;plugin&gt;
    &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
    &lt;artifactId&gt;maven-antrun-plugin&lt;/artifactId&gt;
    &lt;executions&gt;
      &lt;execution&gt;
        &lt;phase&gt;process-classes&lt;/phase&gt;
        &lt;goals&gt;
          &lt;goal&gt;run&lt;/goal&gt;
        &lt;/goals&gt;
      &lt;/execution&gt;
    &lt;/executions&gt;
    &lt;configuration&gt;
      &lt;tasks&gt;
        &lt;taskdef name="instrument" classname="org.hibernate.tool.instrument.javassist.InstrumentTask"&gt;
          &lt;classpath&gt;
            &lt;path refid="maven.runtime.classpath" /&gt;
            &lt;path refid="maven.plugin.classpath" /&gt;
          &lt;/classpath&gt;
        &lt;/taskdef&gt;
        &lt;instrument verbose="false"&gt;
          &lt;fileset dir="${project.build.outputDirectory}"&gt;
            &lt;include name="**/*.class"&gt;&lt;/include&gt;
          &lt;/fileset&gt;
        &lt;/instrument&gt;
      &lt;/tasks&gt;
    &lt;/configuration&gt;
  &lt;/plugin&gt;
  </code></pre>