hibernate 缓存问题 IE缓存问题 还是其他?
项目中利用hibernate来控制数据层,使用二级缓存配置文件如下:
- Java code
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </prop> <prop key="hibernate.cache.use_query_cache">true</prop> <prop key="hibernate.cache.provider_class"> org.hibernate.cache.EhCacheProvider </prop> </props> </property> <property name="mappingResources"> <list> <value>cn/qdrk/strive/model/JzGtype.hbm.xml</value>
vo类如下:
- Java code
<hibernate-mapping> <class name="cn.qdrk.strive.model.JzGtype" table="jz_gtype"> <cache usage="read-write"/> <id name="gtId" type="java.lang.Integer"> <column name="gt_id" /> <generator class="native"></generator> </id> <property name="gtName" type="java.lang.String"> <column name="gt_name" length="100" not-null="true" /> </property> <property name="gtMark" type="java.lang.String"> <column name="gt_mark" length="200" /> </property> </class></hibernate-mapping>
种类的编辑页面如下:
- HTML code
<html>
<head>
<title>修改客户种类信息 </title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link href="css/home.css" rel="stylesheet" type="text/css">
</head>
<html:javascript formName="guesttypeForm" />
<body>
<%
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
%>
<html:form method="post" action="/guesttype.do?method=addGuestype&bsid=${bsid}>id=${gtid}">
<input type="hidden" name="cp" value="${currentPage}" />
<table width="506" height="160" border="0" cellpadding="0" cellspacing="0" style="border: 2px #6999CA solid;" class="style14">
<tr> <td colspan="2" height="34" align="center" class="style_title">客户种类修改 </td> </tr>
<tr> <td height="25"> </td> <td align="left">
业务: <html:text property="bsname" size="20" readonly="true"> </html:text>
客户种类: <html:text property="gt_name" size="20"> </html:text> </td> </tr>
<tr> <td height="40"> </td> <td align="left">描述: <html:textarea property="gt_mark" cols="55" rows="2"> </html:textarea> </td> </tr>
当我对客户种类进行编辑后,在进行编辑时页面中的内容是原先的数据,我把VO类中的<cache usage="read-write"/>去掉,仍然会出现这个问题,但是在IE工具->internate选项中删除缓存就好了,这是我设置的二级缓存的问题还是IE浏览器的问题?
[解决办法]
页面里加了
<%
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
%>
就不需要了...
应该是2级缓存
先clear一下
再flush一下
[解决办法]
在你操作数据的前面加org.hibernate.Session.clear
后面加org.hibernate.Session.flush
如果用spring的话
getHibernateTemplate().clear();
getHibernateTemplate().flush();
[解决办法]
this.getSession().clear();
gtype = (JzGtype) this.getSession().load(JzGtype.class, gtid);
this.getSession().flush();
>_< 再不行就把load改get吧 跳过2级缓存!