私はStruts 2とHibernateを使用しています。私は、特定のアクションがいつ行われたかについての情報を格納するDateフィールドを持つシンプルなテーブルを持っています。この日付の値はjspに表示されます。 私が持っている問題は、hibernateがdbを更新した後、jspページが日付の値を更新しないということです。実施例のように:私は手動で(F5)更新するとHibernateのキャッシュ?
date1 = 22/06/11 15:00:00
date2 = 22/06/11 16:00:00
は、それはOKです - (すなわち、午後3時から午後4時まで)date1
からdate2
に日付値が変化します。しかし、私がリフレッシュし続ければ、JSPは一度date1とnext2のdate2を表示します。 私はhibernate.cfgに次き:
<property name="hibernate.cache.use_second_level_cache">false</property>
<property name="hibernate.cache.use_query_cache">false</property>
I)は(フラッシュ)(Hibernateの追い出しで実験しました。私は(はい、私は知っている - スクリプトレットは悪い習慣です)スクリプトレットを追加してみました:
<%
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
%>
私は少しはここにこだわっている - すべてのヘルプは高く評価しました。
おかげで、 ダモ
EDIT: は、私はすべてのDAOを拡張DaoEngineクラスを、持っています。
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エンティティマネージャ)の管理やクリーンアップにはどのようなメカニズムを使用していますか? –