title: Hibernate reading function shows old data
body: <p>I've a problem showing data from database. If I update an object, sometimes I get the old data, sometimes the new one. Update function works well (I can see in DB the right update) while the read function seems to get cached data. I've tried to disable both caches, tried to open and close session during update/save, but it's still not working.
  Both User and Store beans have Lazy fetches.
  Thanks!</p>
  
  <p>READ FUNCTION:</p>
  
  <pre><code>    public static List&lt;Store&gt; getStoreByUser(User user)
          throws HibernateException {
      List&lt;Store&gt; result = null;
      Session session = sessionFactory.getCurrentSession();   
      Transaction transaction = null;
      try {
          transaction = session.getTransaction();
          Criteria criteria = session.createCriteria(Store.class);
          criteria.add(Restrictions.eq("userUserID", user));
          result = criteria.list();
      } catch (HibernateException he) {
          logger.error("No Store found for user: = " + user, he);
          throw he;
      }
      return result;
  }
  </code></pre>
  
  <p>UPDATE/SAVE FUNCTION:</p>
  
  <pre><code>    public static Integer insertOrUpdateStore(Store store)
          throws HibernateException {
      Integer id = null;
      Session session = sessionFactory.getCurrentSession();   
      Transaction transaction = null;
      try {
                      transaction = session.getTransaction();
          if (store.getStoreID() != null &amp;&amp; store.getStoreID() != 0) {
  
              session.merge(store);
              transaction.commit();
  
          } else {
                  id = (Integer) session.save(store);
              transaction.commit();               
          }
      } catch (HibernateException he) {
          if (transaction != null) {
              transaction.rollback();
          }
      } finally {
      }       
      return id;
  }
  </code></pre>