在使用hibernate开发项目时,为什么进行更新以后,在才进行预览还是以前的数据,数据库里面的数据明明已经更新了,为什么还是预览的以前的数据呀,是延迟加载?还是缓存的问题?

解决方案 »

  1.   

    加事务了么?
    事务没提交吧
    一般都用spring管理事务
      

  2.   

    看是不是hibernate缓存啊
       你看看 你预览的时候  后台有没有 hibernate发出查询语句啊
     如果没有 他就是直接在缓存里面拿到老数据啊
      

  3.   

    建议你看看你的Hibernate的配置文件,是否允许缓存
      

  4.   

    检查下你的缓存设置,再检查下事物提交么,看看spring管理事物中的配置
      

  5.   

    看有没有发sql语句,再看看配置!
      

  6.   

    按照LZ所说的情况分析,有两种可能会这样。第一种:LZ是在一个事务还是在两个不同的事务中做这样的事呢?如果是两个不同的事务中一个更新,一个获取,这样应该不会出现这个问题,如果是在一个事务中,那么就有可能是事务的问题,而且LZ是调用API更新过后马上就获取吗?如果这样就是因为还没提交事务的原因,如果用容器管理事务,是在方法执行到最后一步才会提交事务的,所以如果是这样,只要在一个事务中,容器会自动管理事务的存取,应该就没什么问题。第二种:如果不是上诉所说,那么LZ在提交事务的时候可以手工试试session.flush或关闭session,再重新获取试试。
      

  7.   

    项目没有使用spring支持  是struts+hibernate  支持 下面是hibernate.cfg.xml文件的配置
    <hibernate-configuration> <session-factory>
    <property name="connection.username">sa</property>
    <property name="connection.url">
    jdbc:sqlserver://localhost:1433;databaseName=luzheng
    </property>
    <property name="dialect">
    org.hibernate.dialect.SQLServerDialect
    </property>
    <property name="myeclipse.connection.profile">luzheng</property>
    <property name="connection.password">123456</property>
    <property name="connection.driver_class">
    com.microsoft.sqlserver.jdbc.SQLServerDriver
    </property>
    <property name="show_sql">true</property>
    <mapping resource="com/jw/writ/entity/Client.hbm.xml" />
    <mapping resource="com/jw/writ/entity/OtherGoods.hbm.xml" />
    <mapping resource="com/jw/writ/entity/Users.hbm.xml" />
    <mapping resource="com/jw/writ/entity/OtherThings.hbm.xml" />
    <mapping resource="com/jw/writ/entity/Writ.hbm.xml" />
    <mapping resource="com/jw/writ/entity/CorrectNotice.hbm.xml" />
    <mapping resource="com/jw/writ/entity/Hearing.hbm.xml" />
    <mapping resource="com/jw/writ/entity/LawAccording.hbm.xml" />
    <mapping resource="com/jw/writ/entity/Cases.hbm.xml"></mapping>
    <mapping resource="com/jw/writ/entity/OverCarInfo.hbm.xml" />
    <mapping resource="com/jw/writ/entity/InCarInfo.hbm.xml" />
    <mapping resource="com/jw/writ/entity/Include.hbm.xml" />
    <mapping resource="com/jw/writ/entity/Goven.hbm.xml" />
    <mapping resource="com/jw/writ/entity/Caseinfo.hbm.xml" />
    <mapping resource="com/jw/writ/entity/Modelinfo.hbm.xml" />
    <mapping resource="com/jw/writ/entity/Ruleinfo.hbm.xml" />
    <mapping resource="com/jw/writ/entity/Bcase.hbm.xml" />
    <mapping resource="com/jw/writ/entity/Organinfo.hbm.xml" />
    <mapping resource="com/jw/writ/entity/Officersinfo.hbm.xml" />
    <mapping resource="com/jw/writ/entity/Parameterinfo.hbm.xml" />
    <mapping resource="com/jw/writ/entity/Qanswerinfo.hbm.xml" />
    <mapping resource="com/jw/writ/entity/Sclient.hbm.xml" />
    <mapping resource="com/jw/writ/entity/Question.hbm.xml" />
    <mapping resource="com/jw/writ/entity/Message.hbm.xml" />
    </session-factory></hibernate-configuration>
      

  8.   

    更新时显示调用session.flush,清理掉缓存
      

  9.   

    更新时显示调用session.flush,清理掉缓存