title: Hibernate lazy loading modifying values
body: <p>I'm working on extending a REST API written in Java using the Spring framework, Hibernate ORM and Jackson for JSON (de)serialization.</p>
  
  <p>On a few API calls, I need to return a user's account given a provided value (say, a subscription ID). There are different types of accounts, so a type value is included so the client can determine what kind of account they're dealing with.</p>
  
  <p>In my controller, I pass the provided user ID down to the service call which calls this method:</p>
  
  <pre><code>public Account getAccountBySubscriptionId(long subscriptionId) {
      ServiceSubscription subscription = subscriptionDAO.load(subscriptionId);
      if(subscription != null) {
          return subscription.getAccount();
      } else {
          return null;
      }
  }
  </code></pre>
  
  <p>I would expect this to return JSON similar to this:</p>
  
  <pre><code>{
      "type":"account_type_goes_here",
      "id":1,
      "accountNumber":"100"
  }
  </code></pre>
  
  <p>However, it appears that Hibernate's lazy loading is modifying the type value, as such (note that UserAccount is the class of the object):</p>
  
  <pre><code>{
       "type":"UserAccount_$$_javassist_1",
       "id":2,
       "accountNumber":"37"
  }
  </code></pre>
  
  <p>How could I make Hibernate retain the original value for type instead of modifying it?</p>