I've got a problem showing data from a database. If I update an object, sometimes I get the old data, and sometimes the new one. The Update function works well (I can see the right update in the DB), while the read function seems to get cached data. I've tried to disable both caches, and tried to open and close session
during update/save, but it's still not working.
Both User and Store beans have Lazy fetches.
READ FUNCTION:
public static List<Store> getStoreByUser(User user)
throws HibernateException {
List<Store> 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;
}
UPDATE/SAVE FUNCTION:
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 && 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;
}