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

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top