title: Spring Data JPA loads one to one relationship in two queries
body: <p>I have following classes:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Data
  @Entity
  @Table(name = "user_info")
  public class UserIdentity implements UserDetails {
    @Id
    private Long id;
    private String username;
    private String password;
    private String facebookId;
    private String phoneNumber;
    private Timestamp unblockDate;
    @OneToOne(fetch = FetchType.EAGER, optional = false)
    @Fetch(FetchMode.JOIN)
    @JoinColumn(name = "role_id")
    private Role role;
  
    }
  
  @Data
  @Entity
  @Table(name = "role")
  public class Role {
    @Id
    private Long id;
    private String name;
    @ManyToMany
    @Fetch(FetchMode.JOIN)
    @JoinTable(name = "role_permission", joinColumns = @JoinColumn(name = "role_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "permission_id", referencedColumnName = "id"))
    private List&lt;Permission&gt; permissions;
  }
  
  @Data
  @Entity
  @Table(name = "permission")
  public class Permission {
    @Id
    private Long id;
    private String name;
  }
  </code></pre>
  
  <p>And when I'm querying for user identity I can see these two queries generated in log:</p>
  
  <pre><code>Hibernate: select useridenti0_.id as id1_3_, useridenti0_.facebook_id as facebook2_3_, useridenti0_.password as password3_3_, useridenti0_.phone_number as phone_nu4_3_, useridenti0_.role_id as role_id7_3_, useridenti0_.unblock_date as unblock_5_3_, useridenti0_.username as username6_3_ from user_info useridenti0_ where useridenti0_.facebook_id=?
  Hibernate: select role0_.id as id1_1_0_, role0_.name as name2_1_0_, permission1_.role_id as role_id1_2_1_, permission2_.id as permissi2_2_1_, permission2_.id as id1_0_2_, permission2_.name as name2_0_2_ from role role0_ left outer join role_permission permission1_ on role0_.id=permission1_.role_id left outer join permission permission2_ on permission1_.permission_id=permission2_.id where role0_.id=?
  </code></pre>
  
  <p>But I expect to see only one query. Can you please help me to find out what I'm doing wrong?</p>
  
  <p><strong>UPDATE</strong>
  I'm using CrudRepositor:</p>
  
  <pre class="lang-java prettyprint-override"><code>public interface UserIdentityRepository extends CrudRepository&lt;UserIdentity, Long&gt; {
    UserIdentity findByFacebookId(String facebookId);
    UserIdentity findByPhoneNumber(String phoneNumber);
  }
  </code></pre>
  
  <p>and I noticed following thing - if I search using method <em>findById()</em> it works as expected, but if I use <em>findByPhoneNumber()</em> then it doesn't work.</p>