Thread:
 Problem with subclasses 
 PerJacobsson   26 Oct 2007, 17:41 

Comment
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
From: PerJacobsson (26 Oct 2007, 17:41) Replies: 0, Views: 1272
Subject: Problem with subclasses
We were getting ClassCastExceptions when subclassing a subclass of
GenericHibernateDAO. This change to the constructor will fix it:

public GenericHibernateDAO() {
    Class clazz = getClass();
    while (!(clazz.getGenericSuperclass() instanceof ParameterizedType)) {
        clazz = clazz.getSuperclass();
    }
    	
    persistentClass = (Class<T>) ((ParameterizedType)
clazz.getGenericSuperclass()).getActualTypeArguments()[0];
}
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
© Copyright 2006, Red Hat Middleware, LLC. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc. [Privacy Policy]