title: Why is Spring-Data-JPA Async not working?
body: <p>I am trying to create a non-blocking rest service with Spring Boot and Spring data JPA. </p>
  
  <p>How to do Async save of an entity with Spring Data JPA @Async support. Below code is not working for me although other selects seem to be working on the same entity. </p>
  
  <p>I am trying to do this within a JPA Repository. Here is full repository : except for save.  These methods are working fine and I could test them</p>
  
  <pre><code>public interface LoanRepository extends JpaRepository&lt;Loan,Long&gt; {
  
  @Query("select distinct loan from Loan loan left join fetch loan.collaterals left join fetch loan.partys")
  @Async
  CompletableFuture&lt;List&lt;Loan&gt;&gt; findAllWithEagerRelationships();
  
  @Query("select loan from Loan loan left join fetch loan.collaterals left join fetch loan.partys where loan.id =:id")
  @Async
  CompletableFuture&lt;Loan&gt; findOneWithEagerRelationships(@Param("id") Long id);
  
  @Async
  void delete(Long id);
  </code></pre>
  
  <p>}</p>
  
  <p>However, when I try to add the below save method : </p>
  
  <pre><code>    @Async
      &lt;S extends CompletableFuture&lt;Loan&gt;&gt; S save(Loan loan);
  </code></pre>
  
  <p>I get an obvious compilation error which says <code>"The method save(Loan) is ambiguous for the type LoanRepository"</code></p>
  
  <p>I tried changing it to : </p>
  
  <pre><code>    @Async
      &lt;S extends CompletableFuture&lt;Loan&gt;&gt; S save(S loan);
  </code></pre>
  
  <p>But I get an exception at startup <code>java.lang.UnsupportedOperationException: null</code> which is due to :</p>
  
  <pre><code>Caused by: java.lang.NullPointerException: null
  at org.springframework.data.repository.query.QueryMethod.potentiallyUnwrapReturnTypeFor(QueryMethod.java:244)
  </code></pre>
  
  <p>The Spring Data JPA Documentation on Async support is not clear on Save part of it.  <a href="http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-async" rel="nofollow">Spring Data JPA Async Support</a></p>