Created
December 8, 2012 10:09
-
-
Save rvazquezglez/4239684 to your computer and use it in GitHub Desktop.
Clase auxiliar que hereda de HibernateDaoSupport.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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