您的位置:首页 > 职场人生

漫画:为什么不能打断程序员?

2013-10-29 23:07 489 查看
Hibernate comes with three different caches: first level, second level and query cache.
The first level cache is the Hibernate Session and is used to track the state of entities during the current Session (or unit of work). This is a transaction-level cache.
The second level cache shares entity state across various Session. This is a SessionFactory-level cache.
The query cache is used to cache queries (and their parameters) and their results.

steps to use cache
add ehcache dependency, enable following in conf
hibernate.cache.use_query_cache=true
hibernate.cache.use_second_level_cache=true
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
## If the cache is used in a JTA environment, you must specify the property
## Hibernate.transaction.manager_lookup_class and naming a strategy for obtaining the JTA TransactionManager.
hibernate.transaction.manager_lookup_class=com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup

put following tag in entities hibernate mapping file
[code=xml]

<!--details see office document-->
<cache usage="transactional|read-write|nonstrict-read-write|read-only" />
<set>
<cache usage="transactional|read-write|nonstrict-read-write|read-only" />
</set>


The Second Level Cache in the documentation
Hibernate: Truly Understanding the Second-Level and Query Caches
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: