Quantcast
Channel: Java Programming Forum - Learn Java Programming - Hibernate
Viewing all articles
Browse latest Browse all 76

"automatically" DAO

$
0
0
Hi,
I don't know if it's possible, and if yes, how can I do it... I'm developing a web app using JAVA and Hibernate. To any Class I must have a DAO.

Question: Can I have only one DAO to all classes ?

The idea is... If I have 10 Classes, I'll able to use the same DAO for all of them, for example:

public void add (Entity entity) {
Session session = ConnectionFactory.getSession();
Transaction transaction = null;
try {
gettransaction = session.beginTransaction();
session.save(entity);
transaction.commit();
} catch (HibernateException e) {
transaction.rollback();
e.printStackTrace();
} finally {
session.close();
}
}

Where Entity would be any Class... Is it possible ? If yes, how can I do it ?

Regards..

Viewing all articles
Browse latest Browse all 76

Trending Articles