I have omitted many details from the code below just to keep it simple.
Is my implementation right?
Is there any downside of this implementation?
Is there a better way of implementing the same?
MyAction.java
class MyAction {
public String execute() {
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
try {
UserLoginDAO uldao = new UserLoginDAOImpl();
uldao.firstMethod(session);
List l = uldao.secondMethod(session);
tx.commit();
} catch(HibernateException ex) {
if(tx != null) tx.rollback();
} finally {
session.close();
}
//statements
}
}
UserLoginDAOImpl.java
class UserLoginDAOImpl implements UserLoginDAO{
public void firstMethod(session) {
//statements
session.save(something);
}
public List secondMethod(session) {
//statements
List lst = session.createQuery("something").list();
//statements
}
}
UserLoginDAO.java
interface UserLoginDAO {
public void firstMethod(session);
public List secondMethod(session);
}