开发者

hibernate proxy

开发者 https://www.devze.com 2022-12-25 06:58 出处:网络
load() just returns a proxy by default and database won’t be hit until the proxy is first invoked. what does it mean by p开发者_开发技巧roxy exactly here ?First of all, Proxy is a design pattern. In

load() just returns a proxy by default and database won’t be hit until the proxy is first invoked.

what does it mean by p开发者_开发技巧roxy exactly here ?


First of all, Proxy is a design pattern. In sense of Hibernate, it is dynamically subclassing your object at runtime. The proxy object will contain the same methods as your object(that's why you don't realize that you are dealing with a proxy), and as you say the database won’t be hit until the proxy is first invoked.


To explain further about proxies; they are created dynamically by extending(creating a sub class) of your object at runtime. This subclass has all the methods of the parent entity, and when any of the methods are accessed, the proxy loads up the real object from the DB and calls the method for you. Additionally , it is worth to mention that all the typecasting and the instanceof operator works perfectly fine on the proxy as it is a direct subclass, hence typically you are not required to perform any special operation in realization that you have a proxy instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号