Skip to content

Instantly share code, notes, and snippets.

@rvazquezglez
Created December 8, 2012 10:09
Show Gist options
  • Save rvazquezglez/4239684 to your computer and use it in GitHub Desktop.
Save rvazquezglez/4239684 to your computer and use it in GitHub Desktop.
Clase auxiliar que hereda de HibernateDaoSupport.
package net.javagurus.hibernate.dao;
import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import org.hibernate.HibernateException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public class GenericDAO<T, ID extends Serializable> extends HibernateDaoSupport {
// La clase que herede quedaria de la siguiente forma:
// public class BancoDAO extends GenericDAO<Banco, BigDecimal>
private Class<T> clasePersistente;
public GenericDAO () {
clasePersistente = (Class<T>) ((ParameterizedType) getClass()
.getGenericSuperclass()).
getActualTypeArguments()[0];
}
public void save(T entidad) throws HibernateException {
getHibernateTemplate().save(entidad);
}
public void update(T entidad) throws HibernateException {
getHibernateTemplate().update(entidad);
}
public void delete(T entidad) throws HibernateException {
getHibernateTemplate().delete(entidad);
}
public T get(ID id) throws HibernateException {
return (T) getHibernateTemplate().get(clasePersistente, id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment