Thanks a lot for the reply.
I read the reference recently. I want to confirm the following thing:
(1) when coding in a session bean with container-managed tranaction, I just return from the methods when everything is fine, or call EJBContext.setRollbackOnly() when I want to rollback the tranaction.
Can I still do it in Hibernate the same way as I did before?
I means whether the following code in a session bean is still correct:
Session hibernateSession = null ;
try
{
hibernateSession = sessionFactory.openSession();
C c = new C();
c.setAddress("foo bar");
s.save(c);
} catch ( Exception e )
{
ejbContext.setRollbackOnly() ;
} finally
{
if ( s != null ) s.close();
}
Note that I do not call begin*() to start a transaction. I hope Hibernate will enlist the global transaction managed by EJB container.
(2)Can I open a session in each DAO( i.e, every dao has a call to openSession() )? These DAOs participate in the same transaction.
|