title: Should I use Java 8 default methods for manually implemented Spring Data repository methods?
body: <p>When using the new Spring Data Evans release it's nice to be able to use some of the nice stuff that came with java 8. One of them is default implementations in interfaces. The repository below uses QueryDSL to make queries type safe.</p>
  
  <p>My problem is that before when I wrote this I used the pattern of a separate <code>UserRepositoryCustom</code> interface for the <code>findByLogin</code> and then another class <code>UserRepositoryImpl</code> and in that class I would have the <code>@PersistenceContext</code> to get the current <code>EntityManager</code>.</p>
  
  <p>How do I get the <code>EntityManager</code> when I don't have a class? Is it even possible?</p>
  
  <pre><code>@Repository
  public interface UserRepository extends JpaRepository&lt;User, UUID&gt; {
  
      final QUser qUser = QUser.user;
  
      // How do I get the entityManager since this is a interface, i cannot have any variables?
      //@PersistenceContext
      //EntityManager entityManager;
  
      public default Optional&lt;User&gt; findByLogin(String login) {
          JPAQuery query = new JPAQuery(entityManager);
          User user = query
                  .from(qUser)
                  .where(
                          qUser.deleter.isNull(),
                          qUser.locked.isFalse(),
                          qUser.login.equalsIgnoreCase(login)
                  )
                  .singleResult(qUser);
  
          return Optional.ofNullable(user);
      }
  }
  </code></pre>