title: How does the FetchMode work in Spring Data JPA
body: <p>I do have a relation between three model object in my project (model and repository snippets in the end of the post. </p>
  
  <p>When I call <code>PlaceRepository.findById</code> it does fire three select queries:</p>
  
  <p>("sql")</p>
  
  <ol>
  <li><code>SELECT * FROM place p where id = arg</code></li>
  <li><code>SELECT * FROM user u where u.id = place.user.id</code></li>
  <li><code>SELECT * FROM city c LEFT OUTER JOIN state s on c.woj_id = s.id where c.id = place.city.id</code></li>
  </ol>
  
  <p>That's rather unusual behavior (for me). As far as I can tell after reading Hibernate documentation it should always use JOIN queries. There is no difference in the queries when <code>FetchType.LAZY</code> changed to  <code>FetchType.EAGER</code> in the <code>Place</code> class (query with additional SELECT), the same for the <code>City</code> class when <code>FetchType.LAZY</code> changed to  <code>FetchType.EAGER</code> (query with JOIN). </p>
  
  <p>When I use <code>CityRepository.findById</code> suppressing fires two selects: </p>
  
  <ol>
  <li><code>SELECT * FROM city c where id = arg</code></li>
  <li><code>SELECT * FROM state s where id = city.state.id</code></li>
  </ol>
  
  <p>My goal is to have a the sam behavior in all situations (either always JOIN or SELECT, JOIN preferred though). </p>
  
  <p>Model definitions:</p>
  
  <p>Place:</p>
  
  <pre><code>@Entity
  @Table(name = "place")
  public class Place extends Identified {
  
      @Fetch(FetchMode.JOIN)
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = "id_user_author")
      private User author;
  
      @Fetch(FetchMode.JOIN)
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = "area_city_id")
      private City city;
      //getters and setters
  }
  </code></pre>
  
  <p>City: </p>
  
  <pre><code>@Entity
  @Table(name = "area_city")
  public class City extends Identified {
  
      @Fetch(FetchMode.JOIN)
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = "area_woj_id")
      private State state;
      //getters and setters
  }
  </code></pre>
  
  <p>Repositories: </p>
  
  <p>PlaceRepository</p>
  
  <pre><code>public interface PlaceRepository extends JpaRepository&lt;Place, Long&gt;, PlaceRepositoryCustom {
      Place findById(int id);
  }
  </code></pre>
  
  <p>UserRepository: </p>
  
  <pre><code>public interface UserRepository extends JpaRepository&lt;User, Long&gt; {
          List&lt;User&gt; findAll();
      User findById(int id);
  }
  </code></pre>
  
  <p>CityRepository: </p>
  
  <pre><code>public interface CityRepository extends JpaRepository&lt;City, Long&gt;, CityRepositoryCustom {    
      City findById(int id);
  }
  </code></pre>