首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

springMVC3.0+hibernate3.0缓存有关问题

2013-07-08 
springMVC3.0+hibernate3.0缓存问题请问一下,我使用springMVC3.0+hibernate3.0框架,现在使用JS做一个仿照Q

springMVC3.0+hibernate3.0缓存问题
请问一下,我使用springMVC3.0+hibernate3.0框架,现在使用JS做一个仿照QQ农场的应用,农场的状态是查询数据库数据,并根据当前时间来改变农场植物状态并更新到数据库中。现在的问题就是,改变了农场状态,更新到数据库中后,我对页面进行刷新,农场的状态有可能会恢复到没更新之前的状态,再刷新又可能是出现更新后的状态。我试过在debug状态对其内存进行查看,在读数据库时,读到的数据有可能跟数据库数据不一样,但是只要我重启tomcat服务器后,怎么刷新读到的数据也会跟数据库的数据一样。初步怀疑是hibernate缓存问题,但是hibernate配置中是没有使用二级缓存的,hibernate配置如下:

<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/examfarm?useUnicode=true&amp;characterEncoding=UTF-8</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.format_sql">false</property>
<property name="hibernate.use_sql_comments">false</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.cache.use_second_level_cache">flase</property>
<property name="hibernate.cache.use_query_cache">flase</property>
<property name="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</property>

mysql缓存配置如下:
+------------------------------+----------------------+
| Variable_name                | Value                |
+------------------------------+----------------------+
| binlog_cache_size            | 32768                |
| binlog_stmt_cache_size       | 32768                |
| have_query_cache             | YES                  |
| key_cache_age_threshold      | 300                  |
| key_cache_block_size         | 1024                 |


| key_cache_division_limit     | 100                  |
| max_binlog_cache_size        | 18446744073709547520 |
| max_binlog_stmt_cache_size   | 18446744073709547520 |
| metadata_locks_cache_size    | 1024                 |
| query_cache_limit            | 1048576              |
| query_cache_min_res_unit     | 4096                 |
| query_cache_size             | 0                    |
| query_cache_type             | ON                   |
| query_cache_wlock_invalidate | OFF                  |
| stored_program_cache         | 256                  |
| table_definition_cache       | 400                  |
| table_open_cache             | 256                  |
| thread_cache_size            | 8                    |
+------------------------------+----------------------+

现在不知道是哪个缓存问题导致这个结果,请各位大侠帮我分析一下,谢谢
Hibernate Cache springmvc 数据库


[解决办法]
建议在业务层缓存数据,使用ehcache比较不错呢...可以参考下我的博客的项目实例
[解决办法]
是不是有其他连接在操作数据库, 你session范围就查询不到更新数据了。

热点排行