From: Achmad A. R. <a.a...@gm...> - 2005-10-12 04:59:21
|
Hi sivester, getActualTypeArguments are instance of TypeVariableImpl, and we cannot cast it into Class. Am I missing something ? thnx On 10/10/05, Bijl, Silvester van der <sil...@lo...> wrote: > > Hi, > > I've been playing around with this. I came up with the following code: > > > public class AbstractBaseHibernateDao<ObjectType, IdType extends > Serializable> extends > HibernateDaoSupport implements BaseDao<ObjectType, IdType> { > > // JDK 5.0 trickery to retrieve the object class > private Class ourClass =3D > (Class)((ParameterizedType)getClass().getGenericSuperclass()).getActualTy= peArguments()[0]; > > /* > * Retrieve object from db. > */ > @SuppressWarnings("unchecked") > public ObjectType get(IdType id) throws DataAccessException { > return (ObjectType) getHibernateTemplate().load(ourClass, id); > } > > } > > I declared the interface similiar to your code. Hope this helps. > > Silvester > > ________________________________ > > Van: spr...@li... namens Achmad > Arif Rachim > Verzonden: di 11-10-2005 6:33 > Aan: spr...@li...; > jug...@ya... > Onderwerp: [Springframework-developer] How create Generic DAO pattern in > tiger > > > How to read Inherit Generic Type class ? > > Guys I've been googling all week but couldn't find solution. > > Id like to create Generic DAO pattern. So here's what i do > > public interface Dao<E extends Entity, I extends Serializable>{ > public I create(E entity); > public E read(I id); > public void update(E entity); > public E delete(I id); > } > > concrete class would be like this > > public class DaoBean implements Dao{ > public Serializable create(Entity entity){ > getHibernateTemplate.save(entity); > return entity.getId(); > } > public void update(Entity entity){ > getHibernateTemplate.update(entity); > } > public Entity read(Serializable id){ > return (Entity)getHibernateTemplate.load(getClass(),id); > } > public Entity delete(Serializable id){ > Entity entity =3D read(id); > getHibernateTemplate.delete(entity); > return entity; > } > > public Class getEntityClass(){ > // now ... how to get Dao E class ???? > return E.class; > } > } > > The millon dollar* question is how to get Dao Generic E type class ??? > (* million asked question) > > Thanx > > > This e-mail and any attachment is for authorised use by the intended > recipient(s) only. It may contain proprietary material, confidential > information and/or be subject to legal privilege. It should not be copied= , > disclosed to, retained or used by, any other party. If you are not an > intended recipient then please promptly delete this e-mail and any > attachment and all copies and inform the sender. Thank you. > > |