Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType

807589Nov 6 2008 — edited Nov 7 2008
On the hibernate website I found some sample code of a generic DAO implementation.
However when I try to execute it, it throws the ClassCastException java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType

The sample code:
public interface GenericDAO<T, ID extends Serializable> {

    T findById(ID id, boolean lock);

    List<T> findAll();

    List<T> findByExample(T exampleInstance);

    T makePersistent(T entity);

    void makeTransient(T entity);
}
public abstract class GenericHibernateDAO<T, ID extends Serializable>
        implements GenericDAO<T, ID> {

    private Class<T> persistentClass;
    private Session session;

    public GenericHibernateDAO() {
        this.persistentClass = (Class<T>) ((ParameterizedType) getClass()
                                .getGenericSuperclass()).getActualTypeArguments()[0];
     }

....
Any idea on what is going wrong?

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 5 2008
Added on Nov 6 2008
3 comments
3,903 views