我正在使用Struts 2和Hibernate。我有一个带有日期字段的简单表格,用于存储有关某个操作何时发生的信息。此日期值显示在我的jsp中。 我遇到的问题是,休眠更新数据库后,jsp页面不会更新日期值。作为一个工作示例:Hibernate缓存?
date1 = 22/06/11 15:00:00
date2 = 22/06/11 16:00:00
当我手动(F5)刷新那么它的确定 - 日期值的变化从date1
到date2
(即从15:00至16:00)。但是如果我保持清爽,那么jsp将会显示date1和next time date2等等。 我在hibernate.cfg如下:
<property name="hibernate.cache.use_second_level_cache">false</property>
<property name="hibernate.cache.use_query_cache">false</property>
我尝试用Hibernate的逐出(),刷新()。我尝试添加一个小脚本(是的,我知道 - 小脚本是不好的做法):
<%
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
%>
我有点困在这里 - 任何帮助表示赞赏。
感谢, 达摩
编辑: 我有一个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();
}
}
您使用什么机制来管理和清理Hibernate会话(或JPA实体管理器)? –