什么是Hibernate的一级和二级缓存? [英] What are First and Second Level caching in Hibernate?

查看:63
本文介绍了什么是Hibernate的一级和二级缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以用简单的语言解释一下Hibernate中的第一级和第二级缓存是什么?

解决方案

1.1)一级缓存


一级缓存总是与会话对象关联。 Hibernate默认使用这个缓存。在这里,它处理一个
交易后另一个交易,意味着不会处理一笔交易多
次。主要是它减少了它在给定事务中产生的
所需的SQL查询的数量。这不是在事务完成后每更改
后更新,而是仅在事务结束时更新事务


1.2)二级缓存


二级缓存总是与会话工厂对象。在运行事务时,它会在Session Factory级别加载
对象,以便这些对象对于整个应用程序可用
,而不会绑定到单个用户。从
开始,对象已经被加载到缓存中,只要对象是查询返回的
,那时就不需要去执行数据库
事务。这样二级缓存就可以工作。在这里,我们也可以使用
查询级别缓存。


引用自: http://javabeat.net/introduction-to-hibernate-caching/


Can anyone explain in simple words what First and Second Level caching in Hibernate are?

解决方案

1.1) First-level cache

First-level cache always Associates with the Session object. Hibernate uses this cache by default. Here, it processes one transaction after another one, means wont process one transaction many times. Mainly it reduces the number of SQL queries it needs to generate within a given transaction. That is instead of updating after every modification done in the transaction, it updates the transaction only at the end of the transaction.

1.2) Second-level cache

Second-level cache always associates with the Session Factory object. While running the transactions, in between it loads the objects at the Session Factory level, so that those objects will be available to the entire application, not bound to single user. Since the objects are already loaded in the cache, whenever an object is returned by the query, at that time no need to go for a database transaction. In this way the second level cache works. Here we can use query level cache also.

Quoted from: http://javabeat.net/introduction-to-hibernate-caching/

这篇关于什么是Hibernate的一级和二级缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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