I've got an interesting problem w/ my webapp displaying stale data on a page refresh.
I've done a lot of searching and have found what looks like correct answers, but nothing has worked.
I'm making ajax calls to update some objects, but when I refresh the page (or go back and enter through the action) I do not always see the changes. I can see them in the database of course.
Any help will be much appreciated.
The Hibernate classes are in a jar sitting inside JBoss. The webapp is in a .war inside JBoss (not my decision), and I'm using JNDI for the datasource.
The save method is as follows :
Code:
public void updateAGroupDefinition(GroupDefinition groupDefinitionToUpdate)
{
Transaction tx = null;
try
{
tx = HibernateSessionFactory.getSession().beginTransaction();
this.groupDefinitionDAO.attachDirty(groupDefinitionToUpdate);
tx.commit();
HibernateSessionFactory.getSession().flush();
}
catch (Exception e)
{
tx.rollback();
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
finally
{
HibernateSessionFactory.getSession().flush();
HibernateSessionFactory.getSession().close();
}
}
The dao method (MyEclipse generated and not my code) being called is :
Code:
public void attachDirty(GroupDefinition instance) {
log.debug("attaching dirty GroupDefinition instance");
try {
getSession().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
The read method is :
Code:
try
{
String queryString = "from ExtCustomerCodeDefinition as model where model.code = ? and model.delete = 'N'";
Session sess = getFreshSession();
sess.setFlushMode(FlushMode.ALWAYS);
Query queryObject = sess.createQuery(queryString);
queryObject.setParameter(0, codeToFind);
System.out.println(queryObject.getQueryString());
ExtCustomerCodeDefinition retVal = (ExtCustomerCodeDefinition) queryObject.list().get(0);
log.debug("Found : " + retVal);
try
{
ExtGroupDefinition topGroup = retVal.getTopGroup();
log.debug("\t" + topGroup);
if(topGroup.getGroups() != null)
{
for(ExtGroupDefinition childGroup : topGroup.getGroups())
{
log.debug("\t" + childGroup);
}
}
}
catch (NoHierarchyException e)
{
log.debug("\t With no top group");
}
return retVal;