What is Hibernate proxy?

Showing Answers 1 - 12 of 12 Answers

Class can be mapped to a proxy instead to a table. When you actually call load on session it returns you proxy. This proxy may contain actual method to load the data.

May be used when you already some pre-existing code for persistence and you want to call it via Hibernate

  Was this answer useful?  Yes

Proxies are created dynamically by subclassing your object at runtime. The subclass has all the methods of the parent, and when any of the methods are accessed, the proxy loads up the real object from the DB and calls the method for you. Very nice in simple cases with no object hierarchy. Typecasting and instanceof work perfectly on the proxy in this case since it is a direct subclass.

when we call the load() method as given below
                             session.load(empObject);
 here it is showing that empObject is loaded.But in practicality load() method is lazy loading so it is going to create proxy class and when we call the value in the table using getter method in that instance it will touch the database and give the data form database to session object.i.e empObject.getEname(); when we call this method in that instance it will touch the database and put the data into session object.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions