It's ok but you can try use some framework (Spring for example) or application server to automatically manage transactions. If you want to try Spring read this: http://docs.spring.io/spring/docs/3.0.x/reference/transaction.html
Coherent usage of Hibernate's session and DAO [closed]
Pergunta
Here is my code
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.
Thanks
Solução
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow