title: Spring, CGLIB: why can't a generic class be proxied?
body: <p>I'd like to ask about <strong>the root cause</strong> of the exception:</p>
  
  <pre class="lang-none prettyprint-override"><code>Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to  
  java.lang.reflect.ParameterizedType
  </code></pre>
  
  <p>which happens in Spring when we make Spring generate proxies for classes (i.e. setting <code>proxy-target-class="true"</code> on a transaction manager):</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;tx:annotation-driven transaction-manager="transactionManager" 
  proxy-target-class="true"/&gt;
  </code></pre>
  
  <p>and when the class to proxy is a parameterized class, i.e.</p>
  
  <pre class="lang-java prettyprint-override"><code>public class SomeDAOImpl&lt;SomeEntity&gt; implements SomeDAO ...
  </code></pre>
  
  <p>The full story can be, for example, read in this question: <a href="https://stackoverflow.com/q/3852564/838434">Abstract DAO pattern and Spring&#39;s &quot;Proxy cannot be cast to ...&quot; problem!</a></p>
  
  <p><strong>Question:</strong> why can't Spring proxy this class? Is it because it uses old code generation libraries? Because of type erasure? If the <code>SomeDAOImpl</code> was not a generic class, it would succeed (I checked that).</p>
  
  <p>Please don't answer like: "you should proxy interfaces, not classes". I know that.</p>