I know a proxy object is :
我知道代理对象是:
Proxies are the mechanism that allows Hibernate to break up the interconnected cloud of objects in the database into smaller chunks, that can easily fit in memory.
代理是一种机制,允许Hibernate将数据库中互连的对象云分解成更小的块,这些块可以很容易地放入内存中。
- What I am trying to figure out is, how does hibernate do it behind the scenes and how is it implemented by hibernate?
- 我想弄清楚的是,hibernate是如何在幕后完成的,它是如何通过hibernate实现的?
- I mean how is it cached in the memory ? Is it a first level cache or second level cache ? Is there any good read for this ?
- 我的意思是它是如何缓存在内存中的?它是一级缓存还是二级缓存?这有什么好的读物吗?
1 个解决方案
#1
3
Hibernate use javassist to create dynamic proxies instead of concrete entities to populate fields of fetched entity that are referencing other persistent entity (or collection of persistent entities).
Hibernate使用javassist创建动态代理而不是具体实体来填充引用其他持久实体(或持久实体集合)的获取实体的字段。
(note that if you mark the relationship as eagerly fetched : hibernate won't create proxies but concrete entities. This is NOT the default)
(请注意,如果您将关系标记为急切获取:hibernate将不会创建代理,而是具体实体。这不是默认值)
A major advantage of javassist over standard dynamic proxy mechanism is that it allows creation of dynamic proxy on concrete classes, not only interfaces.
与传统标准动态代理机制相比,javassist的一个主要优点是它允许在具体类上创建动态代理,而不仅仅是接口。
The responsability of a proxy is to perform "transparently" a database read operation when required (i.e. when access to a proxied entity is required)
代理的责任是在需要时“透明地”执行数据库读取操作(即,当需要访问代理实体时)
Proxies and first or second level cache aren't really linked concepts. We can just say that if you try to "resolve" a proxy when the entity holding it isn't attached to an open session (i.e. when the entity holding it isn't in the first level cache) it will raise a LazyInitializationException (simply because there is no way perform a database read in this situation)
代理和第一级或第二级缓存不是真正链接的概念。我们可以说,如果你试图“解析”代理,当持有它的实体没有附加到开放会话时(即当持有它的实体不在第一级缓存中时),它将引发一个LazyInitializationException(简单地说)因为在这种情况下无法执行数据库读取)
#1
3
Hibernate use javassist to create dynamic proxies instead of concrete entities to populate fields of fetched entity that are referencing other persistent entity (or collection of persistent entities).
Hibernate使用javassist创建动态代理而不是具体实体来填充引用其他持久实体(或持久实体集合)的获取实体的字段。
(note that if you mark the relationship as eagerly fetched : hibernate won't create proxies but concrete entities. This is NOT the default)
(请注意,如果您将关系标记为急切获取:hibernate将不会创建代理,而是具体实体。这不是默认值)
A major advantage of javassist over standard dynamic proxy mechanism is that it allows creation of dynamic proxy on concrete classes, not only interfaces.
与传统标准动态代理机制相比,javassist的一个主要优点是它允许在具体类上创建动态代理,而不仅仅是接口。
The responsability of a proxy is to perform "transparently" a database read operation when required (i.e. when access to a proxied entity is required)
代理的责任是在需要时“透明地”执行数据库读取操作(即,当需要访问代理实体时)
Proxies and first or second level cache aren't really linked concepts. We can just say that if you try to "resolve" a proxy when the entity holding it isn't attached to an open session (i.e. when the entity holding it isn't in the first level cache) it will raise a LazyInitializationException (simply because there is no way perform a database read in this situation)
代理和第一级或第二级缓存不是真正链接的概念。我们可以说,如果你试图“解析”代理,当持有它的实体没有附加到开放会话时(即当持有它的实体不在第一级缓存中时),它将引发一个LazyInitializationException(简单地说)因为在这种情况下无法执行数据库读取)