Hi
I am using Hibernate 2.1. My web application is comprised of Presentation, business and data layers.
1. The business layer has a stateless session bean which calls DAO in the data layer.
2. The DAO gets session from SessionFactory calling its openSession method.
3. DAO then begins transaction, calls session.saveOrUpdateCopy(), commits the transaction, and finally calls closeSession().
I am under the impression that stateless session bean will start a transaction upon the entry in any of its method. DAO's begin transaction should join the current transaction. My question is, do DAO's calls to commit the transaction and closing the session cause actual update in the database ? If yes, how will session bean's setRollbackOnly() works ?
My assumption is Hibernate just does the commit to the session cache and at the end of session bean's method, actual commit to the database happens. Is it correct ?
If my assumption is wrong, how would you suggect to handle a session and a transaction so I can call session bean's setRollbackOnly to rollback the transaction in case of an exception in business layer ?
Thank you.
Ram Mahajan
|