休眠缓存级别1 [英] Hibernate cache level 1

查看:129
本文介绍了休眠缓存级别1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对高速缓存级别1有一个误解。到目前为止,我已经看到高速缓存级别1仅用于延迟sql调用,直到事务刷新。



但是对象呢?例如,我只使用高速缓存级别1.如果我要在1次事务中多次加载相同的对象,会发生什么情况? hibernate是否使用某种标识映射并缓存已在1个事务中加载的对象?

>到目前为止,我已经看到高速缓存级别1仅用于阻止sql调用,直到事务被刷新。


简而言之,第一级缓存仅仅是一个从id(主键)到保存与该主键关联的状态的对象的映射。

但是你不应该将会话和事务概念混为一谈,它们不是一回事(并且会话不一定是事务范围的)。


如果我在一次事务中多次加载同一个对象,会发生什么情况?

只有一个对象表示数据库中给定的行(即给定的id)。这就是为什么管理状态成为可能,这是第一级缓存的重点。


hibernate是否使用某种标识映射和缓存对象已在1笔交易中加载

请参阅上文。

I have one misunderstanding of cache level 1. So far I've seen that cache level 1 is used only to put off sql invocations until a transaction is flushed.

But what about objects? For instance, I use only cache level 1. If I were to load the same object several times within 1 transaction, what would happen? Does hibernate use some sort of identity map and caches objects which has been loaded within 1 transaction?

解决方案

So far I've seen that cache level 1 is used only to put off sql invocations until a transaction is flushed.

To put it simply, the first level cache is just a map from id (primary key) to an object that holds the state associated with that primary key.

But you shouldn't mix session and transaction concepts, they are not the same thing (and a session is not necessarily transaction scoped).

If I were to load the same object several times within 1 transaction, what would happen?

There will be only one object representing a given row in the database (i.e. for a given id). That's what makes managing state possible and that's the whole point of the 1st level cache.

Does hibernate use some sort of identity map and caches objects which has been loaded within 1 transaction

See above.

这篇关于休眠缓存级别1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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