EJB design: Which transaction to use Database transactions or ejb ?

  1. Hi,

    Which the better way of using transactions. Should I use jdbc transactions or should I use bean managed ejb transactions? What are pros and cons of each?

  2. Hi,
          U r question is not clear but if ur using BMP Entity Beans use Bean managed transation, JTS is already implemented by the Application Server Vendor so u will get good Transaction Control through Bean Container.

    (vindhyachalsharma at yahoo dot com)
  3. Im my earlier project this is the architecture I have used. Data Access Objects (no entity beans, normal java classes) were used to do database operations. These DAOs were called from a stateless session bean. So the db connection lookup was made from the ejb, and instead of using jtx.begintransaction, we were using connection.begintransaction. That is jdbc transactions, instead of ejb transactions. What is the difference between these two? Which approach is better?
  4. I've understood that the preferred way would be to use the UserTransaction object (from JNDI tree, provided by appserver) to begin, commit, and rollback transactions. That is, of course, if we're not using container managed transactions.

    So, what have I misunderstood if anything?
  5. Well,

    You should differ code transactions and data transactions here. Using JTA and bean managed transaction demarcations you have a chance of rolling back/commiting not only the data, but code as well. JTA transactions will automatically start JDBC transactions for you either.