title: Class cannot be cast to java.lang.reflect.ParameterizedType
body: <p>Currently the <code>VariableService</code> is <code>@Autowired</code> in my controller.</p>
  
  <p>I realize I can implement  the class <code>ParameterizedType</code> to make this error go away but I fear that I may be headed in the wrong direction.  Is there a better way to do this or do I need to bite the bullet and implement <code>ParameterizedType</code>'s methods?</p>
  
  <blockquote>
    <p>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contentController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.fettergroup.cmt.service.VariableService com.fettergroup.cmt.web.ContentController.variableService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'variableService' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.fettergroup.cmt.service.VariableService]: Constructor threw exception; nested exception is java.lang.ClassCastException: <strong>java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType</strong></p>
  </blockquote>
  
  <p><strong>Variable Service</strong></p>
  
  <pre><code>public class VariableService extends EntityService {
      public VariableService () {
          super.setEntityRepository(new VariableRepository());
      }
  }
  </code></pre>
  
  <p><strong>EntityService</strong></p>
  
  <pre><code>public abstract class EntityService&lt;T&gt; {
  
      public EntityRepository&lt;T&gt; entityRepository;
  
      public T create(T entity) {
          return entityRepository.create(entity);
      }
  
      public T update(T entity) {
          return entityRepository.update(entity);
      }
  
      public void delete(T entity) {
          entityRepository.delete(entity);
      }
  
      public void setEntityRepository(EntityRepository&lt;T&gt; entityRepository) {
          this.entityRepository = entityRepository;
      }
  }
  </code></pre>
  
  <p><strong>Variable Repository</strong></p>
  
  <pre><code>public class VariableRepository extends EntityRepository {
  
  }
  </code></pre>
  
  <p><strong>EntityRepository</strong></p>
  
  <pre><code>@Repository
  public abstract class EntityRepository&lt;T&gt; {
  
      //the equivalent of User.class
      protected Class&lt;T&gt; entityClass;
  
      @PersistenceContext(type= PersistenceContextType.TRANSACTION)
      public EntityManager entityManager;
  
      public EntityRepository () {
          //Get "T" and assign it to this.entityClass
          ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass();
          this.entityClass = (Class&lt;T&gt;) genericSuperclass.getActualTypeArguments()[0];
      }
  
      /**
       * Create this entity
       * @param t
       * @return 
       */
      public T create(T t) {
          entityManager.persist(t);
          return t;
      }
  
      /**
       * Update this entity
       * @param t
       * @return 
       */
      public T update(T t) {
          return entityManager.merge(t);
      }
  
      /**
       * Delete this entity
       * @param entity 
       */
      public void delete(T t) {
          t = this.update(t);
          entityManager.remove(t);
      }
  
      public void setEntityManager(EntityManager entityManager) {
          this.entityManager = entityManager;
      }
  }
  </code></pre>