Refère toi à la doc hibernate : Generic Data Access Objects
à l'adresse :
http://www.hibernate.org/328.html
En voici un extrait :
"This is a pattern for Data Access Objects with JDK 5.0, from the
CaveatEmptor example application. Two links you might find useful: Sessions and transactions and Open Session in View.
This time I based the DAO example on interfaces. Tools like Hibernate already provide database portability, so persistence layer portability shouldn't be a driving motivation for interfaces. However, DAO interfaces make sense in more complex applications, when several persistence services are encapsulate in one persistence layer, and they deserve more than a note (which was all I did in HiA first edition).
The DAO interfaces
I use one interface per persistent entity, with a super interface for common CRUD functionality:
public interface GenericDAO<T, ID extends Serializable> {
T findById(ID id, boolean lock);
List<T> findAll();
List<T> findByExample(T exampleInstance);
T makePersistent(T entity);
void makeTransient(T entity);
}
You can already see that this is going to be a pattern for a state-oriented data access API, with methods such as makePersistent() and makeTransient(). Furthermore, to implement a DAO you have to provide a type and an identifier argument. As for most ORM solutions, identifier types have to be serializable. [...]"
ça devrait te contenter. je crois. si j'ai compris la question.