I have implemented
nested transactions to handle transaction from business layer: implement business level transactions that span multiple data layers.
So here is how it works in my business layer:
MyBusinessController
Code:
openSession() as currentSession() using SessionContext
openTransaction()
dataController1.executeMethod()
dataController2.executeMethod()
commutTransaction()
rollbackTransaction() in case of exception
DataContrller1.executeMethod()Code:
read currentSession
read transaction
--if transaction is already open then use it, else open a new transaction
--execute SQL statements
--commit the transaction iff it is a new transaction opened here, else continue
flush the session
DataContrller2.executeMethod()Code:
read currentSession
read transaction
--if transaction is already open & active then use it, else open a new transaction
--execute SQL statements
--commit the transaction iff it is a new transaction opened here, else continue
flush the session
This way a new transaction is open in business layer and same is used in data layers. Let me know if you need sample code for this implementation.