public void something(){    Session session = HibernateUtil.newSession();    AModelDAO amd = new AModelDAO(session);    BModelDAO bmd = new BModelDAO(session);    Transaction tx = session.beginTransaction();    amd.savesomething(object);    bmd.savesomething(object2);    tx.commit();    session.close();}I would like to know if my coding here is good enough or if there is a better method to produce the same result.
Coherent usage of Hibernate's session and DAO
java;session;hibernate
Instead of working with Hibernate sessions, I encourage you to use the JPA API. I think this is the most common way to work with Hibernate now. (http://www.theserverside.com/news/2240186700/The-JPA-20-EntityManager-vs-the-Hibernate-Session-Which-one-to-use)For the transaction aspects and the initialization of your DAOs, I also think that a solution like Spring (http://projects.spring.io/spring-framework/) would help to simplify the code of your application.Your code would look more like the following (with annotations stuff):public class MyService {  @Resource  private AModelDAO aDao;  @Transactional  public void something(object) {    // no need to manage transactions or sessions here    aDao.save(object);  }}