you could use generics and meditations to do something like this
public interface IDao<T> { public <A extends Serializable> T getElementByID(A x); public Long getRowsCount(); public List<T> getAll(); public List<T> getAll(String order); public void saveOrUpdateElement(T x); public void updateElement(T x); public void saveElement(T x); public void deleteElement(T x); public void setClase(Class<T> clase); public Class<T> getClase(); public void mergeElement(T x); public T getFirst();
}
method public void setClase (class clase); do all the magic, so if you need to request x, then you will set the class, and the implementation, for example, getAll () will be
public List<T> getAll(){ return session.createQuery("from "+getClase().getSimpleName()).list();
}
source share