0 Replies Latest reply on Jan 12, 2012 10:20 AM by Sascha Möllering

    Class cast exception

    Sascha Möllering Newbie

      Hello,

       

      my current setup looks like this:

       

      1) JBoss 7.1.0 CR1

      2) One DAO (Stateless-Session-Bean) extending an abstract class for generic hibernate-access:

       

      public abstract class AbstractHibernateDao<T, PK extends Serializable>

          implements GenericDaoIntf<T, PK> {

       

          /**

           * The persistent class.

           */

          protected Class<T> persistentClass;

       

          /**

           * The Hibernate session.

           */

          protected Session session;

       

         

      @SuppressWarnings("unchecked")

          protected AbstractHibernateDao() {

             

              setPersistentClass((Class<T>) ((ParameterizedType) getClass()

                                             .getGenericSuperclass()).getActualTypeArguments()[0]);

             

      ....

      ....

       

      @Stateless

      public class ApplicationHibernateDao extends AbstractHibernateDao<Application, String> {

       

          private static final int MAX_RESULTS = 1000;

         

          @Override

          public Application findByPrimaryKey(String id) {

              return (Application) session.get(Application.class, id);

          }

       

       

      ...

      ...

       

      The problem is: setPersistentClass throws:

       

      Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType

       

      Any hints?

       

       

      Regards,

      Sascha