EJB programming & troubleshooting: transactions - JDBC and container managed transaction
- Posted by: I Gordon
- Posted on: July 06 2001 03:34 EDT
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.
- transactions - JDBC and container managed transaction by Bernhard Messerer on July 06 2001 06:09 EDT
- transactions - JDBC and container managed transaction by Stephen Davies on July 06 2001 23:36 EDT
- transactions - JDBC and container managed transaction by Prince George on August 23 2001 09:41 EDT
- transactions - JDBC and container managed transaction by Kent Roylance on July 12 2001 12:50 EDT
- transactions - JDBC and container managed transaction by Kent Roylance on July 13 2001 16:37 EDT
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
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.
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.
I would recommend using Container Manager Persistence whenever you can.
I meant Container Managed Transactions.