title: What does the Hibernate proxy object contain?
body: <p>All I could gather from Google is that:</p>
  
  <ul>
  <li><p>Hibernate uses a proxy object to implement lazy loading.
  When we request to load the Object from the database, and the fetched Object has a reference to another concrete object, Hibernate returns a proxy instead of the concrete associated object.</p></li>
  <li><p>Hibernate creates a proxy object using bytecode instrumentation (provided by javassist). Hibernate creates a subclass of our entity class at runtime using the code generation library and replaces the actual object with the newly created proxy.</p></li>
  </ul>
  
  <p>So, what exactly does the Proxy object contain? </p>
  
  <p>Does it contain a skeleton object reference object with only the id field set? Others field will be set when we call the get method? </p>
  
  <p>Does the Proxy object contain the JDBC statement to fetch all data required to fully populate the referenced object.</p>
  
  <p>Is there something else I might be missing?</p>
  
  <p>I am not asking for spoon feeding but if you can provide any link with information that would be great.</p>
  
  <p>Any correction to above description will also be welcomed.</p>
  
  <p>Example.</p>
  
  <pre><code>class Address {
     String city;
     String country;
  }
  
  class Person{
     int id;
     String name;
     Address address;
  }    
  </code></pre>
  
  <p>When we try to load the Person object, Hibernate will subclass Person class like:</p>
  
  <pre><code>class ProxyPerson extends Person {
         int id;
         String name;
         Address proxyCGLIBObject;
  }
  </code></pre>
  
  <p>and return a ProxyPerson object. Object of ProxyPerson  will have a value for id and name but proxy for Address.</p>
  
  <p>Am I correct?</p>
  
  <p>What can I expect from adding a toString() method on the proxy object?</p>