Hello all. I've just completed my first Hibernate application, and am wondering how I can better organise my code. I've put all my Hibernate calls into one class (DataManager) which is over 500 lines long, containing loads of methods which perform some sql. Each method creates and commits a session. Please see the code example below, and let me know if this is a horrible design, how it can be improved etc.
Code:
public class DataManager{
public Long insertValue1(String value) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Object o; // create my object
Long id = (Long)session.save(o);
session.getTransaction().commit();
return id;
}
public Long insertValue2(String value) {
// as above with different object
}
public List getObjects(){
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List result = session.createQuery("My query")
.setString(0, username).list();
session.getTransaction().commit();
return result;
}
public List getFoo(){
// as above with different objects
}
// you get the idea, loads more methods doing the same thing with different sql...
}
Is this kind of normal, or is there some better way? Thanks!