项目中利用hibernate来控制数据层,使用二级缓存配置文件如下:<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类如下:<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_" length="200" />
        </property>
       </class>
</hibernate-mapping>种类的编辑页面如下:<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}&gtid=${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">
 业务:&nbsp;<html:text property="bsname" size="20"  readonly="true"></html:text>&nbsp;&nbsp;&nbsp;&nbsp;
         客户种类:&nbsp;<html:text property="gt_name" size="20"></html:text></td></tr>
  <tr><td  height="40"></td><td align="left">描述:&nbsp;<html:textarea property="gt_"  cols="55" rows="2"></html:textarea></td></tr>当我对客户种类进行编辑后,在进行编辑时页面中的内容是原先的数据,我把VO类中的<cache usage="read-write"/>去掉,仍然会出现这个问题,但是在IE工具->internate选项中删除缓存就好了,这是我设置的二级缓存的问题还是IE浏览器的问题?

解决方案 »

  1.   

    页面里加了 <%
     response.setHeader("Pragma","No-cache");
     response.setHeader("Cache-Control","no-cache");
     response.setDateHeader("Expires", 0);
    %>
    就不需要了...应该是2级缓存
    先clear一下再flush一下
      

  2.   

    升星啦,散分没?没... >_< 
      

  3.   

    在你操作数据的前面加org.hibernate.Session.clear
    后面加org.hibernate.Session.flush如果用spring的话
    getHibernateTemplate().clear();
    getHibernateTemplate().flush();
      

  4.   

    这是我查询的语句:public JzGtype getGuestypeById(String id) {
    int gtid = Integer.parseInt(id);
    JzGtype gtype = null;
    gtype = (JzGtype) this.getSession().load(JzGtype.class, gtid);
    return gtype;
    }其他的和他一样啊,怎么就可以呢?
      

  5.   

    查询出来是可以...
    你做了修改后2级缓存里没有同步
    所以就这样了...
    >_<
      

  6.   


    public JzGtype getGuestypeById(String id) {
    int gtid = Integer.parseInt(id);
    JzGtype gtype = null;
    getHibernateTemplate().clear(); 
    gtype = (JzGtype) this.getSession().load(JzGtype.class, gtid);
    getHibernateTemplate().flush();
    return gtype;
    }我这么写不管用啊。
      

  7.   

     this.getSession().clear(); 
     gtype = (JzGtype) this.getSession().load(JzGtype.class, gtid);
     this.getSession().flush();>_< 再不行就把load改get吧 跳过2级缓存! 
      

  8.   


    public JzGtype getGuestypeById(String id) {
    int gtid = Integer.parseInt(id);
    JzGtype gtype = null;
    /*getHibernateTemplate().clear(); 
    gtype = (JzGtype) this.getSession().load(JzGtype.class, gtid);
    getHibernateTemplate().flush();*/
    gtype =(JzGtype)this.getSession().get(JzGtype.class,gtid);
    return gtype;
    }日,我改成这样也不行。