title: Spring @Transactional and Neo4j OGM session.getTransaction()
body: <p>What is the correlation between Spring <code>org.springframework.transaction.annotation.Transactional</code> annotation and Neo4j OGM <code>org.neo4j.ogm.session.Session.getTransaction()</code> method.</p>
  
  <p>I'm trying to access the current transaction via <code>session.getTransaction()</code> inside of the method annotated with Spring <code>@Transactional</code> but always getting null.</p>
  
  <p>I have added a following code inside of my Spring MVC RestController method:</p>
  
  <pre><code>Transaction tx = session.beginTransaction();
  try {
          for (int i = 0; i &lt; 10; i++) {
              initializeNode(node);
          }
      }
      tx.commit();
  } catch (Throwable th) {
      logger.error("Error while inserting mock data", th);
      th.printStackTrace();
  } finally {
      tx.close();
  }
  </code></pre>
  
  <p>in case of the following method:</p>
  
  <pre><code>private void initializeNode(TestNode node) {
      System.out.println(session.getTransaction());
  }
  </code></pre>
  
  <p>it prints current tx - so far everything is okay.</p>
  
  <p>But in case of the following method:</p>
  
  <pre><code>private void initializeNode(TestNode node) {
      System.out.println(session.getTransaction());
  
      User admin = userDao.findByUsername("admin");
  }
  </code></pre>
  
  <p>first time it prints current tx and then null... transaction disappear before commit for a some reason..</p>
  
  <p>this is <code>findByUsername</code> method:</p>
  
  <pre><code>@Service
  @Transactional
  public class UserDaoImpl implements UserDao {
  
      @Override
      @Transactional(readOnly = true)
      public User findByUsername(String username) {
          return userRepository.findByUsername(username);
      }
  ...
  }
  </code></pre>
  
  <p>Right after that on commit I'm getting a following exception:</p>
  
  <pre><code>org.neo4j.ogm.exception.TransactionManagerException: Transaction is not current for this thread
      at org.neo4j.ogm.session.transaction.DefaultTransactionManager.commit(DefaultTransactionManager.java:100)
      at org.neo4j.ogm.transaction.AbstractTransaction.commit(AbstractTransaction.java:83)
      at org.neo4j.ogm.drivers.embedded.transaction.EmbeddedTransaction.commit(EmbeddedTransaction.java:77)
  </code></pre>
  
  <p>What am I doing wrong ? Why transaction disappears ?</p>