title: Transaction does not retrieve on time data
body: <p>I have a project with many services. I'm using pure jpa with jersey in my project. </p>
  
  <p>I use entityManager, entityTransaction and entityManagerFactory in this way: for each service I get an EntityManager from DBManager.getEntityManager() and get and entityTransaction from its entityManager</p>
  
  <pre><code>public class DBManager {
      public static EntityManager getEntityManager() {
          return Persistence.createEntityManagerFactory("projectDataSource").getEntityManager();
  }
  </code></pre>
  
  <p>In each method that need transaction, first I check <code>transaction != null</code> and transaction is not active </p>
  
  <p>Then I begin the transaction.</p>
  
  <p>I evict cache and after all of this I do my job: in this example I get all active users from database, and my service that returns users list to client.</p>
  
  <p>One of my services is : <code>@getUsersService</code></p>
  
  <pre><code>public class GetUsersServiceImpl {
  
  private static EntityManager entiyManager = DBManager.getEntityManager();
  private static EntityTransaction entityTransaction = entityManager.getTransaction();
  
  public List&lt;User&gt; getUsers()
      if (transaction != null &amp;&amp; !transaction.isActive())
          transaction.begin()
  
      entityManager.getEntityMangerFactory().getCache().evictAll();
  
      return entityManger.createQuery("SELECT u FROM USER u WHERE u.isActive = true").getResultList();
  }
  </code></pre>
  
  <p>This code works but not always!</p>
  
  <p>I have another service that changes the users; this user also works and changes user data in database, but after calling change service when I call getUsers service, it retrieves old database data</p>
  
  <p>Why does this happen?</p>
  
  <p>Is it correct the way I use entityManager and entityTransaction ...</p>