title: Hibernate query oscillating between two sets of results
body: <p>We have a jsp page on a spring mvc 3 project with hibernate that has two datatables displaying two groups of users.  Clicking on a user's name in one table sends a POST transferring the user to the other group, and then the page is reloaded.  When the page is initially loaded, the data is shown correctly in both tables.  However, after clicking a user to transfer them between groups, the page starts to have issues.  Even though the DB is correctly updated, the following method used to pull users out of the DB for the tables starts oscillating between two sets of values on refreshes of the page.  One set of values returned is correct, while the other is the data before the DB update.  Refreshing this page as many times as wanted will just jump back and forth between the two sets of values ad infinitum.  </p>
  
  <p>We are wondering what could cause a hibernate query to oscillate between returning two sets of values, even though the db is not changed in any way between these hibernate queries.</p>
  
  <pre><code>    Session hibernateSession = Utility.getSession();
      try {
          Query notIn = hibernateSession.createQuery("select endUserGroupEndUsers.endUserEndUserId from Endusergroupendusers endUserGroupEndUsers");
          List&lt;Endusers&gt; notinlist = notIn.list();
      } finally {
          hibernateSession.close();
      }
      return notinlist;
  </code></pre>
  
  <p>Here is our Utility class for hibernate containing the getSession call:</p>
  
  <pre><code>public class Utility {
      private static final SessionFactory ourSessionFactory;
      private static final ServiceRegistry serviceRegistry;
  
      static {
          try {
              Configuration configuration = new Configuration();
              configuration.configure();
  
              serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
              ourSessionFactory = configuration.buildSessionFactory(serviceRegistry);
          } catch (Throwable ex) {
              throw new ExceptionInInitializerError(ex);
          }
      }
  
      public static Session getSession() throws HibernateException {
          return ourSessionFactory.openSession();
      }
  }
  </code></pre>