This is a proxy object to support lazy loading; basically, as soon as you reference the child or lookup object via accessor / getter methods, if the related object is not in the session cache, then the proxy code will be passed to the database and load the associated object. It uses javassist to efficiently dynamically create subclassed implementations of your objects (although I think it can be configured to use CGLIB ).
If it had not been proxied in this way, it would be impossible to implement seamless lazy loading.
I can’t remember the top of my head, regardless of whether you use active loading, a natural object will be returned instead. Normally, I would not recommend using a downloadable load, especially if you have many related child objects, as this could soon become a huge performance bottleneck, as it would suck every related object into memory.
Also, if you need to distinguish between the type of a class, rather than using obj.getClass() , use Hibernate.getClass(obj) , which will return you a class of natural objects whether it is proxied or not: see the Hibernate Javadocs API here .
source share