We are going to devleop a project, in J2ee, in that we are using DAO pattern,
- Posted by: raguvaran nan
- Posted on: December 18 2004 00:22 EST
we are using session beans for EJB and DAO class for Data Access,
So in that case where i have to implement Transactions, in session bean or
in DAO , pls reply with an ideal exampl, it is important.
As a rule of thumb, I would put all transaction demarcation at one layer, and that layer should be at as high a level as is possible. This prevents lower levels (DAOs) from needing to make assumptions about the how they are being called - allowing them to be grouped into larger transactions in the future.
Unless I have a good reason not to, I generally tend to use container managed transaction demarcation (CMT) and specify each session bean method as "Required".
As a rule of thumb, I would put all transaction demarcation at one layer, and that layer should be at as high a level as is possible.
In case you have to use user-defined transactions, you should put this behavior in the entry point to each process, so that each process/service is contained in a single transaction.
What are you using EJB for if not transaction management?
The EJB which is your entry point from outside of the container (usually a SLSB using the session facade pattern) should manager you transaction whether explicity or automatically. DAOs should be passed connections and should not do any transaction control.