session.clear();是清空一级缓存的方法,楼主使用了二级缓存,二级缓存是SessionFactory级的所以要调用SessionFactory的evice()方法去清空

解决方案 »

  1.   

    上边发错了点.
    session.getSessionFactory().evict(DocBean.class);
    我也用了的
    session.refresh(DocBean);
    session.clear();
    session.getSessionFactory().evict(DocBean.class);这几个方法我都用了的
      

  2.   

    DocBean的同步缓存策略是什么?
      

  3.   

    <property name="hibernate.jdbc.use_streams_for_binary">true</property>
    <property name="hibernate.order_updates">true</property>
    <property name="hibernate.connection.autocommit">false</property>
    <property name="hibernate.transaction.auto_close_session">false</property>
    <property name="hibernate.cache.use_query_cache">true</property>
    <property name="hibernate.cache.use_second_level_cache">true</property>
    <property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property其他都是默认的
      

  4.   

    另外我还加了个 default-lazy="false"
      

  5.   

    hibernate 步缓存策略 这个我不清楚
      

  6.   

    那就不太清楚了,不好意思,不过hibernate不建议使用HashTable作为二级缓存,试试第三方的cache
      

  7.   

    我换过其他的ECache 来用,效果一样,
    感觉很奇怪,第一次更没问题.....
      

  8.   

    请问:这些更新已经真正被持久化到表里了吗?
    你可以试验一下来缩小问题的范围:1,关闭Query_Chache, 因为修改数据时Query_Chache绝对没有意义。
    2,关闭二级缓存。
       批量更新:
       for(...){
         pojo = session.load(...)
         session.update(pojo);
         if( i%10 ==0 )
            session.flush();
       }
       session.flush();
       //这时再看看更新了没有?
      

  9.   

    数据已经更新了的,但从cache 中读如老的数据后,又吧数据库的内容更新成老的了.
    有时候更新SQL都没有.
    我在家里电脑上测试了一下,写了个简单的更新,又没什么问题.就是公司的电脑上这个程序有这个问题.
    奇怪啊
      

  10.   

    在加没有打开二级缓存吧,不涉及到缓存同步。
    或者是DocBean这个hbm的同步策略的问题,这个不太确定。
    把DocBean.hbm贴出来吧。
      

  11.   

    这个问题我也碰到过。我的解决方案是:在查询时晴空session.而不是在进行修改时。
    实例代码:
    public List getCgList(Object searchObj, int currentPageNumb) {
    List rtnList = new ArrayList();    
    try {
             String sql = "from Phinfo as phinfo ";  
             sql = sql+getWhereSql(searchObj)+getOrderbySql();
             Query query = this.getSession().createQuery(sql);
             query.setFirstResult(DestributePage.perPageNumb * (currentPageNumb - 1));
             query.setMaxResults(DestributePage.perPageNumb);
             this.getSession().clear(); //晴空缓存
             rtnList = query.list();
            } catch (Exception ex) {
                this.getLogger().error("____hibernate操作错误____", ex);
            }
            return rtnList;
    }
      

  12.   

    <hibernate-mapping default-lazy="false">
        <class name="jspx.jdoc.table.DocPart">
            <id name="id" type="java.lang.String" length="50">
                   <generator class="uuid.hex" />
            </id>
            <property name="partId"  type="java.lang.String" column="partId" length="100"  not-null="true"/>
            <property name="manId"  type="java.lang.String" column="manId" length="50"  not-null="true"/>
            <property name="title"  type="java.lang.String" column="title" length="50"  not-null="true"/>
            <property name="logo"  type="java.lang.String" column="logo" length="200" not-null="false"/>
            <property name="logoLink"  type="java.lang.String" column="logoLink" length="200"  not-null="false"/>
            <property name="sortDate" type="java.util.Date" column="sortDate" not-null="true" />
        </class>
    </hibernate-mapping>
      

  13.   

    终于知道问题了,是使用是 ThreadLocal 方式.的问题.
      

  14.   

    目前的网上通用的 ThreadLocal 方式实现, 在多线程交叉查询的时候并没有很处理.所以解决方法有
    三个
    1.不使用ThreadLocal 方式,用最基本的方式就可以了保证稳定了.
    2.使用的时候不要出现多线程交叉查询,一般很难保证.
    3.修改你的ThreadLocal 类.