2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

What is hibernate proxy and how it works?

What is hibernate proxy and how it works?

userimage

In hibernate proxy is something helps hibernate to load the data or map the data to proxy instance based on the requirement. Proxy are the classes generated dynamically by Hibernate to help with lazy loading. For example if user wants a Class to be loaded with the mapped data from actual table present in database, in that case Proxy helps hibernate to get the required data and map to the proxy instance. Now the first time you will call a method on this proxy and if it is not initialized then it will query the database to load it's attributes and map to the proxy instance. This is possible because the dynamically generated class overrides the base class's methods and adds this initialized/uninitialized check. Hibernate need to load its class's parent and parent's parent and so on. Using proxies enable Hibernate to only load the required instances.

Answer is