title: Temporarily forcing LazyInitializationExceptions
body: <p>Traditionally, we try to <em>avoid</em> <code>LazyInitializationException</code>s. However, I need to <em>temporarily</em> allow them to be thrown. This is the pseudo code of what I'm trying to do:</p>
  <pre><code>Session session = ...;
  
  Customer customer = (Customer) session.get(Customer.class, 56);
  
  // All eagerly fetched data is now in memory.
  
  disconnectSession(session);
  
  // Attempts to access lazy data throw LazyInitializationExceptions.
  // I want to take advantage of this fact to *only* access data that 
  // is currently in memory.
  
  magicallySerializeDataCurrentlyInMemory(customer);
  
  // Now that the in-memory data has been serialized, I want to re-connect
  // the session.
  
  reconnectSession(session);
  </code></pre>
  <p>The <code>magicallySerializeDataCurrentlyInMemory</code> method recursively attempts to serialize in-memory data of <code>customer</code> and its related entities, absorbing <code>LazyInitializationException</code>s along the way.</p>
  <h2>Attempt #1: <code>session.disconnect</code> / <code>session.reconnect</code></h2>
  <p>In this attempt, I used this pattern:</p>
  <pre><code>Connection connection = session.disconnect();
  
  magicallySerializeDataCurrentlyInMemory(customer);
  
  session.reconnect(connection);
  </code></pre>
  <p>Unfortunately, it didn't throw <code>LazyInitializationException</code>s.</p>
  <h2>Attempt #2: <code>session.close</code> / <code>session.reconnect</code></h2>
  <p>In this attempt, I used this pattern:</p>
  <pre><code>Connection connection = session.close();
  
  magicallySerializeDataCurrentlyInMemory(customer);
  
  session.reconnect(connection);
  </code></pre>
  <p>Unfortunately, this rendered the <code>session</code> useless after <code>session.reconnect(connection)</code>.</p>
  <p><strong>How can I <em>temporarily</em> force <code>LazyInitializationException</code>s?</strong></p>