Sleep mode caching?

I use Struts 2 and Hibernate. I have a simple table with a Date field that stores information about when a particular action occurred. This date value is displayed in my jsp. The problem is that after hibernation updates db, the jsp page does not update the date value. As a working example:

date1 = 22/06/11 15:00:00 
date2 = 22/06/11 16:00:00

When I update manually (F5), then it’s OK - the date value changes from date1to date2(i.e. from 15:00 to 16:00). But if I continue refreshingly, then jsp will one day show date1 and the next date date2 and so on. In my hibernate.cfg there is the following:

<property name="hibernate.cache.use_second_level_cache">false</property>
<property name="hibernate.cache.use_query_cache">false</property>

I experimented with Hibernate evict (), flush (). I tried to add a scriptlet (yes, I know - scriptlets are bad practice):

<%
   response.setHeader( "Pragma", "no-cache" );
   response.setHeader( "Cache-Control", "no-cache" );
   response.setDateHeader( "Expires", 0 );
%>

- .

,

EDIT: DaoEngine, DAO.

public class DaoEngine
{

    @SuppressWarnings("unchecked")
    private static final ThreadLocal session = new ThreadLocal();
    private static final SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();

    protected DaoEngine()
    {
    }

    @SuppressWarnings("unchecked")
    public static Session getSession()
    {
        Session hibSession = (Session) DaoEngine.session.get();
        if (hibSession == null)
        {
            hibSession = sessionFactory.openSession();
            DaoEngine.session.set(hibSession);
        }
        return hibSession;
    }

    protected void begin()
    {
        getSession().beginTransaction();
    }

    protected void commit()
    {
        getSession().getTransaction().commit();
    }

    @SuppressWarnings("unchecked")
    protected void rollback()
    {
        try
        {
            getSession().getTransaction().rollback();
        }
        catch (HibernateException e)
        {
        }
        try
        {
            getSession().close();
        }
        catch (HibernateException e)
        {
        }
        DaoEngine.session.set(null);
    }

    @SuppressWarnings("unchecked")
    public static void close()
    {
        getSession().close();
        DaoEngine.session.set(null);
    }

    public void clearAll()
    {
        getSession().clear();
    }
}
+5
2

, jsp 1 date2 ..

, , ?

, Hibernate ThreadLocal. , , ThreadLocal, , .

, close() DaoEngine . , - Struts2.

+4

, ThreadLocal. : - 1. session.close() . 2. spring , .

0

All Articles