title: When use getOne and findOne methods Spring Data JPA
body: <p>I have an use case where it calls the following:</p>
  <pre><code>@Override
  @Transactional(propagation=Propagation.REQUIRES_NEW)
  public UserControl getUserControlById(Integer id){
      return this.userControlRepository.getOne(id);
  }
  </code></pre>
  <p>Observe the <code>@Transactional</code> has <strong>Propagation.REQUIRES_NEW</strong> and the repository uses <strong>getOne</strong>. When I run the app, I receive the following error message:</p>
  <pre><code>Exception in thread &quot;main&quot; org.hibernate.LazyInitializationException: 
  could not initialize proxy - no Session
  ...
  </code></pre>
  <p>But If I change the <code>getOne(id)</code> by <code>findOne(id)</code> all works fine.</p>
  <p>BTW, just before the use case calls the <strong>getUserControlById</strong> method, it already has called the <strong>insertUserControl</strong> method</p>
  <pre><code>@Override
  @Transactional(propagation=Propagation.REQUIRES_NEW)
  public UserControl insertUserControl(UserControl userControl) {
      return this.userControlRepository.save(userControl);
  }
  </code></pre>
  <p>Both methods are <strong>Propagation.REQUIRES_NEW</strong> because I am doing a simple <strong>audit</strong> control.</p>
  <p>I use the <code>getOne</code> method because it is defined in the <a href="http://docs.spring.io/spring-data/jpa/docs/1.6.0.RELEASE/api/org/springframework/data/jpa/repository/JpaRepository.html" rel="noreferrer">JpaRepository</a> interface and my Repository interface extends from there, I am working with JPA of course.</p>
  <p>The <strong>JpaRepository</strong> interface extends from <a href="http://docs.spring.io/spring-data/data-commons/docs/current/api/org/springframework/data/repository/CrudRepository.html" rel="noreferrer">CrudRepository</a>.
  The <code>findOne(id)</code> method is defined in <code>CrudRepository</code>.</p>
  <p>My questions are:</p>
  <ol>
  <li>Why fail the <code>getOne(id)</code> method?</li>
  <li>When I should use the <code>getOne(id)</code> method?</li>
  </ol>
  <p>I am working with other repositories and all use the <code>getOne(id)</code> method and all work fine, only when I use the <strong>Propagation.REQUIRES_NEW</strong> it fails.</p>
  <p>According with the <strong>getOne</strong> API:</p>
  <blockquote>
  <p>Returns a reference to the entity with the given identifier.</p>
  </blockquote>
  <p>According with the <strong>findOne</strong> API:</p>
  <blockquote>
  <p>Retrieves an entity by its id.</p>
  </blockquote>
  <ol start="3">
  <li><p>When I should use the <code>findOne(id)</code> method?</p>
  </li>
  <li><p>What method is recommended to be used?</p>
  </li>
  </ol>