如何通过外部操作刷新表行? [英] How to get the table rows refreshed by outside operations?

查看:57
本文介绍了如何通过外部操作刷新表行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。



我的项目是一个基于Struts2 + Spring + Hibernate的web项目。

我正在使用MySQL 。

我正在定义bean并应用DI(依赖注入)。

所有bean都有''request''范围,但只有org.springframework.orm.hibernate3 .annotation.AnnotationSessionFactoryBean实例是''singleton''。



Hi.

My project is a web project based on Struts2 + Spring + Hibernate.
And I''m using MySQL.
I''m defining beans and applying DI( Dependency Injection ).
All beans have ''request'' scope, but only org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean instance is ''singleton''.

<bean id="sessionFactory" scope="singleton"

		class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
		<property name="configLocation" value="classpath:hibernate.cfg.xml" />
	</bean>







问题如下。



1.我运行我的项目。



2.我在网络浏览器上连接到我的项目。



http:// localhost:8080 / myproj



3.这里显示我的数据库中的表行。



4.然后,我在PHPMyAdmin上更改了数据库中的一行。



5.我刷新页面,但页面显示未更改的数据。



什么问题是什么?

请帮帮我。




Problems are as following.

1. I run my project.

2. I connected to my project on the web browser.

http://localhost:8080/myproj

3. Here display the table rows in my database.

4. Then, I changed a row in the database on PHPMyAdmin.

5. I refresh my page, but the page is showing the unchanged data.

What''s the problem?
Please help me.

推荐答案

你好,



Hibernate在第一级缓存(Session)或第二级缓存(某些第三方缓存实现)中有两个可以缓存数据的位置。

当您打开Session并将对象加载到其中时,始终使用第一级缓存。您可以更新此对象的所有属性,仅当会话被刷新或关闭时(通过在会话上调用这些方法)才能更新对象的属性持久保存到数据库。



仅当您向映射文件显式添加缓存声明时才使用二级缓存。否则不使用它。



鉴于此,我怀疑你没有正确关闭会话,这就是为什么你能看到这些变化的原因。如果你有二级缓存(EHCache),那么使用以下xml来禁用它。建议不要禁用第一级缓存,并且没有合适的方法来解决这个问题。你可以使用 session.evict(你的对象)从这个缓存中删除你的对象。

Hello,

Hibernate has two possible places where data can get cached, in the first level cache (the Session) or the second level cache (some third party cache implementation).
The first level cache is always used when you open a Session and load an object into it. You can update this object''s properties all you like, its only when the session is flushed or closed (by calling those methods on the session) that the object''s properties are persisted to the database.

The second level cache is only used if you explicitly add caching declarations to your mapping files. Otherwise it is not used.

Given this I suspect that you are not properly closing the session and that''s why you are able to see the changes. If you have second level cache (EHCache) then use following xml to disable it. Disabling first level cache is not recommended and there is not suitable way to di this. You can use session.evict(YOUR OBJECT) to remove your object from this cache though.
<!-- Enable the second-level cache  -->
<property name="hibernate.cache.provider_class">
    net.sf.ehcache.hibernate.EhCacheProvider
</property>
<property name="hibernate.cache.region.factory_class">
    net.sf.ehcache.hibernate.EhCacheRegionFactory
</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.use_structured_entries">true</property>     
<property name="hibernate.cache.generate_statistics">true</property>



问候,


Regards,


这篇关于如何通过外部操作刷新表行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆