I'm about to generate an abstract class for DAOs, so I'm just wandering if it is possible to access generic type at runtime in method with signature public Collection<ENTITY> search()
.
Please, this is the class :
/**
*
* @author Upgrade <Salathiel Genese, Yimga Yimga at salathielgenese@gmail.com>
* @param <ENTITY>
*/
public class DAO<ENTITY extends Entity>
implements DAOAware<ENTITY>
{
@Override
public void delete(ENTITY entity)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public ENTITY save(ENTITY entity)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public ENTITY search(Long id)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Collection<ENTITY> search()
{
return this.getSession().createCriteria(ENTITY.class).list(); // How to retrieve the runtime class of ENTITY
}
protected Session getSession()
{
return this.sessionFactory.getCurrentSession();
}
@Autowired
private SessionFactory sessionFactory;
}
Aucun commentaire:
Enregistrer un commentaire