title: Spring Boot App with Cglib throws InvocationTargetException
body: <p>I am trying to implement the Repository pattern with lazy loading of my entities (I can't use JPA because its a legacy db model). To lazy.load the entities, I am using a cglib MethodInterceptor in order to intercept an entity's getter method, and dynamically hydrate the corresponding property. For example, in the case of an Airport entity, I will lazy load the Terminals property, only if the corresponding getter is called. The whole thing is packaged as a spring boot application.</p>
  
  <p>The repository implementation is given by:</p>
  
  <pre><code>@Component
  public class AirportsRepository implements Repository&lt;Airport, String&gt; {
  
      @Autowired
      private AirportMapper airportMapper;
      @Autowired
      private TerminalMapper terminalMapper;
  
      private List&lt;AirportInterceptor&gt; airportInterceptors = new ArrayList&lt;&gt;();
  
      @Override
      public Airport get(String id) {
          Airport airport = airportMapper.findById(id);
          if(airport != null){
              AirportInterceptor airportInterceptor = new AirportInterceptor(airport, terminalMapper);
              airport = (Airport) Enhancer.create(Airport.class,airportInterceptor);
              this.airportInterceptors.add(airportInterceptor);
              return airport;
          }
          return airport;
      }
  
      @Override
      public void add(Airport entity) {
           //
      }
      @Override
      public void remove(Airport entity) {
           //
      }
  
      @Override
      public void saveChanges(){
          //
  
      }
  
  }
  
  public class Airport
  {
      // ...
  }
  </code></pre>
  
  <p>And the method interceptor:</p>
  
  <pre><code>class AirportInterceptor implements MethodInterceptor {
      private TerminalMapper terminalMapper;
      private Airport airport;
  
      public AirportInterceptor(Airport airport, TerminalMapper terminalMapper){
          this.airport = airport;
          this.terminalMapper = terminalMapper;
      }
  
      @Override
      public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
          if(method.getName().equals("getTerminals") &amp;&amp; method.invoke(obj, args) == null){
              // Hydrate terminals
              List&lt;Terminal&gt; terminals = terminalMapper.findByAirportCode(airport.getId());
              airport.setTerminals(terminals);
          }
          return method.invoke(obj, args);
      }
  
      public void saveChanges(){
          //airportMapper.update(this.airport);
      }
  
  }
  </code></pre>
  
  <p>However, I am having an issue with the repository code when I call Enhancer.create(), which throws a cryptic exception regarding method toString():</p>
  
  <pre><code>Method threw 'java.lang.reflect.InvocationTargetException' exception. Cannot evaluate com.apm.airportservice.entities.Airport$$EnhancerByCGLIB$$d0daae41.toString()
  </code></pre>