强制Hibernate读取数据库并不返回缓存实体 [英] Force Hibernate to read database and not return cached entity
问题描述
在数据库操作中,Hibernate会缓存实体并在下一次请求中返回它们而不读取实际的数据库。我知道这将减少数据库的负载并提高性能。
但是,当这个应用程序仍在建设中时,我需要从每个请求的数据库加载数据(测试原因)。
有什么办法可以强制数据库读取吗?
我确信这个log4j消息的缓存。
返回单例bean'HelloController'的缓存实例
DEBUG [http-bio-8080-exec-42] - Last-Modified [/myApp/../somePageId.html]是:-1
session.refresh(entity)
或 entityManager.refresh(entity)
(如果您使用JPA)给你从数据库的新数据。
I am using Hibernate and Spring for my web application.
In database operation, Hibernate is caching entities and returning them in next request without reading the actual database. I know this will reduce the load on database and improve performance.
But while this app still under construction, I need to load data from database in every request (testing reason).
Is there any way to force database read?
I became sure about the caching from this log4j message.
Returning cached instance of singleton bean 'HelloController'
DEBUG [http-bio-8080-exec-42] - Last-Modified value for [/myApp/../somePageId.html] is: -1
session.refresh(entity)
or entityManager.refresh(entity)
(if you use JPA) will give you fresh data from DB.
这篇关于强制Hibernate读取数据库并不返回缓存实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!