title: @Async is killing Hibernate transaction
body: <p>I am using an Open-Session-In-View transaction model for my REST api like this:</p>
  
  <pre><code>@Override
      public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        sessionFactory.getCurrentSession().beginTransaction();
        chain.doFilter(request, response);
        sessionFactory.getCurrentSession().getTransaction().commit();
  }
  </code></pre>
  
  <p>This work just fine. I wanted to add @Async abilities. So I created:</p>
  
  <pre><code>@Configuration
  @EnableAsync
  public class AsyncConfig implements AsyncConfigurer {
  
      @Override
      @Bean(destroyMethod="shutdown")
      public Executor getAsyncExecutor() {
          ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
          executor.setCorePoolSize(18);
          executor.setMaxPoolSize(18);
          executor.initialize();
          executor.setDaemon(true);
          executor.setWaitForTasksToCompleteOnShutdown(false);
          return executor;
      }
  
      @Override
      public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
          return new SimpleAsyncUncaughtExceptionHandler();
      }
  }
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>@Component
  public class AsyncMarketCaller {
  
      @Inject
      MarketManagerFactory marketManagerFactory;
  
      @Async
      public Future&lt;List&lt;Product&gt;&gt; getProducts(){
  
          MarketManager productManager = marketManagerFactory.obtainMarketManager(market);
          result = productManager.getProducts();
          ....
      }
  }
  </code></pre>
  
  <p>The productManager makes a call to another @Service </p>
  
  <pre><code>@Service
  public class DefaultIdentifierManager implements IdentifierManager{
       @Inject
      UpcEanDAO upcEanDAO;
  
        @Override
      public String getTitleForIdentifier(String identifier){
          UpcEan upcEan = upcEanDAO.find(identifier);
      }
  }
  </code></pre>
  
  <p>however, for  <code>upcEanDAO.find(identifier)</code> I get an exception:</p>
  
  <pre><code>Caused by: org.hibernate.HibernateException: get is not valid without active transaction
  </code></pre>
  
  <p>Before I added the <code>@Async</code> ability to make async calls to <code>getProducts()</code> it worked just fine so I assume that <code>@Async</code> kills the transaction that I opened with Hibernate.</p>
  
  <p>I tried adding based on another answer here, <code>@Transactional</code> to the method annotated with <code>@Async</code> but it doesn't help.</p>
  
  <p>Any idea?</p>
  
  <p><strong>EDITED</strong></p>
  
  <p>I edited the code so </p>
  
  <pre><code>@Component
  public class AsyncMarketCaller {
  
      @Inject
      AsyncMarketService asyncMarketService;
  
      @Async
      public Future&lt;List&lt;Product&gt;&gt; getProducts(){
          asyncMarketService.getProducts();
      }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>@Service
  public class AsyncMarketService {
  
      @Inject
      MarketManagerFactory marketManagerFactory;
  
      @Transactional
      public Future&lt;List&lt;Product&gt;&gt; getProducts()
       ....
  }
  
  }
  </code></pre>
  
  <p>I see in the log </p>
  
  <pre><code>50689 DEBUG [localhost-startStop-1] org.springframework.transaction.annotation.AnnotationTransactionAttributeSource - Adding transactional method 'AsyncMarketService.getProducts' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
  </code></pre>
  
  <p>but it doesn't help. Please note that my method AsyncMarketService.getProducts doesn't call directly the DB, it calls to other methods and only one of them will make the call.</p>
  
  <p>I also added above the one that actually make the call to DB:@Transactional</p>
  
  <p><code>49992 DEBUG [localhost-startStop-1] org.springframework.transaction.annotation.AnnotationTransactionAttributeSource - Adding transactional method 'DefaultIdentifierManager.getTitleForIdentifier' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; '</code>'</p>