import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import java.util.List;
public class GenericDao extends HibernateDaoSupport{
@SuppressWarnings("unchecked")
publicList getObject(T object){
return getHibernateTemplate().findByExample(object);
}
@SuppressWarnings("unchecked")
publicList getAllObjects(Class thisClass){
return getHibernateTemplate().loadAll(thisClass);
}
@SuppressWarnings("unchecked")
publicObject addObject(T object){
return getHibernateTemplate().save(object);
}
@SuppressWarnings("unchecked")
publicvoid updateObject(T object){
getHibernateTemplate().update(object);
}
}
Thursday, February 19, 2009
A neat little DAO for hibernate I came up with
No need to create new DAOs for each project if you use this little gem. Its not in groovy because GMaven has some problems with generics but this has seemed to remove the need to have multiple DAOs for annotated classes that just do basic crud functionality. Check it out and feel free to comment(Not that anyone reads these anyway :-)).
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment