title: Spring data repository find method hangs when called from inside a thread
body: <p>I want to call a find method from a repository and somehow it is blocking the thread and never returns.</p>
  
  <p>We use spring data to create repositories.</p>
  
  <p>I have a test case with this code:</p>
  
  <pre><code>Thread t = new Thread(() -&gt; {
      repository.findById(1); // this line blocks the thread
  }
  t.start();
  t.join();
  </code></pre>
  
  <p>The repository implementation is standard, it works correctly when called from the main thread.</p>
  
  <p>I noticed that spring uses a thread local that contains the current open session. So I tried to bind a new session in the new thread with this code:</p>
  
  <pre><code>EntityManager em = entityManagerFactory.createEntityManager();
  EntityManagerHolder emHolder = new EntityManagerHolder(em);
  TransactionSynchronizationManager.bindResource(entityManagerFactory, emHolder);
  </code></pre>
  
  <p>But it didn't work, the repository call still blocks.</p>
  
  <p>So I tried to use the newly created EntityManager to find a record from the database using the TransactionTemplate like so:</p>
  
  <pre><code>TransactionTemplate template = new TransactionTemplate(transactionManager);
  template.execute((TransactionCallback&lt;Object&gt;) status -&gt;
                  emHolder.getEntityManager().find(User.class, updated.getId()));
  </code></pre>
  
  <p>But it did't work either, the find method blocks the thread as well.</p>
  
  <p>Do you know what a may be doing wrong? Or is it a bug?</p>