transactions - JDBC and container managed transaction


EJB programming & troubleshooting: transactions - JDBC and container managed transaction

  1. Hi,

    I have inherited code where I have a bean (stateless session) where all it's remote methods use container managed transactions. Inside some of these methods JDBC is used directly, sometimes with auto-commit turned on, sometimes not.

    Do these JDBC statements execute in the context of the methods' transactions? If not - is it better to specify that these particular methods do not use container-managed transactions? I have only a couple of cases where the JDBC code is mixed with CMP entity beans access. Mostly either one or the other is used.

    We are using WL 5.1 by the way.

  2. In general, it is not a problem to access JDBC datsources ("resources") from CMP EBs... the call executes in the context of the transaction. You must, however, follow these rules:
    *) Obtain the datsource from the server via JNDI. Do not open a "direct" connextion via JDBC url
    *) Do not enable auto-commit, call commit() or rollback() this will subvert the server's transaction management

    kind regards

  3. Make sure that you get the Connection from a TxDataSource. You will not need to set autocommit false, it should be set this way by WebLogic.
  4. hi all,
    I am using Weblogic4.5. Can you Please tell how to get the connection from TxDataSource? If you could send me a small sample it will be very helpful. Thanks in advance.

  5. I would recommend using Container Manager Persistence whenever you can.
  6. I meant Container Managed Transactions.