Proxy objects

If you are familiar with Java reflection, you have heard of the java.lang.reflect.Proxy class. In a nutshell, you can wrap any object with a proxy and intercept calls to methods of that object using an invocation handler. Many Java frameworks use proxy objects, or manipulate bytecode (also called instrumentation) to modify the behavior of an object. Hibernate uses both ways for different purposes. More importantly, Hibernate implements its own set of wrapper classes for collection types. (Refer to classes in org.hibernate.collection.internal.)

If you fetch an entity, Hibernate doesn't fetch the associated collections if they are marked as lazy fetch. Instead, it waits until you actually try to access the associated collection. As ...

Get Mastering Hibernate now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.