Question

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

Était-ce utile?

La solution

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top