質問

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