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