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

Foi útil?

Solução

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top