title: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
body: <p>I am stuck with this issue for a long time. I searched for this issue for sometime but none of solution worked. </p>
  
  <p>Structure: </p>
  
  <pre><code>public interface GenericDAO&lt;T extends Serializable, ID extends Serializable&gt;
  
  @Repository
  public class AbstractGenericDAO&lt;T extends Serializable, ID extends Serializable&gt; 
      implements GenericDAO&lt;T, ID&gt; {
  
     private Class&lt;T&gt; persistentClass;
  
     @Autowired
     private SessionFactory sessionFactory;
  
     static Logger LOGGER = Logger.getLogger(AbstractGenericDAO.class);
  
  
     @SuppressWarnings("unchecked")
     public AbstractGenericDAO() {
         this.persistentClass = (Class&lt;T&gt;) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
     }
  
     /**
      * @param entity
      * @return T
      * @throws DBException
      */
     @SuppressWarnings("unchecked")
     public T saveEntity(T entity) throws DBException {
         return saveEntity(entity, false);
     }
  
     /**
      * @param entity
      * @param explicitFlush
      * @return T
      * @throws DBException
      */
     @SuppressWarnings("unchecked")
     public T saveEntity(T entity, boolean explicitFlush) throws DBException {
         Session session = getSessionFactory().getCurrentSession();
  
         try {
             session.save(entity);
             if(explicitFlush) {
                 session.flush();
                 session.refresh(entity);
             }
         } catch (HibernateException he) {
             String errorMsg = "Could not save entity. Reason: " + he.getMessage();
             LOGGER.error(errorMsg, he);
             throw new DBException(errorMsg, he);
         }
  
         return entity;
     }
  
     /* (non-Javadoc)
      * @see com.amazon.fc.receive.dbaccess.dao.GenericDAO#getPersistentClass()
      */
     @SuppressWarnings("unchecked")
     public Class&lt;T&gt; getPersistentClass() {
         return persistentClass;
     }
  
     /**
      * @return the sessionFactory
      */
     public SessionFactory getSessionFactory() {
         return this.sessionFactory;
     }
  
     /**
      * @param sessionFactory the sessionFactory to set
      */
     @Autowired
     public void setSessionFactory(SessionFactory sessionFactory) {
         this.sessionFactory = sessionFactory;
     }
  }
  
  public interface ShlkActiveWorkflowDAO 
      extends GenericDAO&lt;ShlkActiveWorkflow, Serializable&gt; 
  
  @Repository
  public class ShlkActiveWorkflowDAOImpl 
      extends AbstractGenericDAO&lt;ShlkActiveWorkflow, Serializable&gt;
      implements ShlkActiveWorkflowDAO
  </code></pre>
  
  <p>I am also using <code>&lt;context:component-scan&gt;</code> in my <code>application-config.xml</code>
      <code>+ &lt;tx:annotation-driven /&gt;</code> in my <code>application-config.xml</code>.</p>
  
  <p>Please provide some information about how to fix this issue.</p>
  
  <pre><code>Exception:
  
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'abstractGenericDAO' 
  
  Constructor threw exception; nested exception is java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:946)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:890)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:479)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:557)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:842)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:416)
      at com.coral.spring.Launcher.&lt;init&gt;(Launcher.java:95)
      at com.coral.spring.Launcher.main(Launcher.java:56)
  Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.workflow.dao.AbstractGenericDAO]: Constructor threw exception; nested exception is     
  java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
      at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141)
      at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:72)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:938)
      ... 12 more
  Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
      at com.workflow.dao.AbstractGenericDAO.&lt;init&gt;(AbstractGenericDAO.java:43)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
      at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)
      ... 14 more
  </code></pre>