Bean Manage Transaction using JDBC API


EJB programming & troubleshooting: Bean Manage Transaction using JDBC API

  1. Bean Manage Transaction using JDBC API (4 messages)

    Hi all,

    I have a stateful sessionbean TransferEJB which has a method Transfer(Sender,Receiver,Amt). The pseudo code of the method are shown below:

    Open connection
    Begin Transaction
    SAmt=ReadDB(Sender) /* Read sender amount from DB */
    RAmt=ReadDB(Reciever) /* Read receiver amouny from DB */
    SAmt = SAmt - Amt
    RAmt = RAmt + Amt
    UpdateDB (Sender, SAmt) /* Update Database */
    UpdateDB (Reciver, RAmt) /* Update Database */
    Commit Transaction

    The connection is created using Datasource:
    | String dbName = "java:comp/env/jdbc/testDB";
    | DataSource ds = (DataSource) initailcontext.lookup (dbName);
    | con = ds.getConnection();
    | con.setTransactionIsolation (Connection.TRANSACTION_REPEATABLE_READ);
    Then I begin the transaction using:
    | con.setAutoCommit(false);
    However, the following error message appear in the log file.
    UnSupported Operation...

    Can I use JDBC API to start Transaction like this. The J2EE specification said that it is allowed to use either JDBC API or JTA API to do Transaction. Why I can't begin the transaction using this method??

    Anyone can help??
    Thank in advance.

    Best regards
    John Chui

  2. Bean Manage Transaction using JDBC API[ Go to top ]

    Which JDBC driver are you using? Not all JDBC drivers support all transaction isolation levels. Write a quick dummy Java program that for each type of isolation level it opens a connection, sets an isolation level, and closes. See what happens (does the code execute until close() is called or is an exception thrown when you try to set the isolation level? I've had this happen to me in the past with Informix's JDBC driver, and it turns out that Informix's JDBC driver doesn't support every isolation level.
  3. Bean Manage Transaction using JDBC API[ Go to top ]

    Thank you for your reply.
    I'm using JDBC:ODBC driver.
    But my main problem is even the con.setAutoCommit(false)
    method can't be called.
    Some JDBC articles said that in global Transaction context, we can't run the command like con.commit and con.setAutoCommit as it is managed by container. What' thst mean and How can I use local Transaction context?
  4. Bean Manage Transaction using JDBC API[ Go to top ]

    Check to see if your EJB has container-managed transactions setup to begin with. If your deployment descriptor is using the default transaction demarcation level, the container may be creating a new transaction before your bean method is called.

    In section 16.3.4 of the specfication, it says you cannot use transactional methods of resource managers for container-managed-persistence. You would get an exception when you attempt to use setAutoCommit(...) in this scenario.

    1) If you really want to do BMP, make sure that the container is not demarcating a transaction around your method. Change the method to supports or none.

    2) Given the design of your method, I don't see why you couldn't use container managed transactions. The behavior you are trying to accomplish would be the same behavior ultimately given to you by a CMT.

  5. hi,
      Can you tell me some about jdbc for informix?
    Because I meet such situation:
      I use weblogic5.1,visual cafe4.0 to make a ejb. when I use visual cafe, at the step of persistencebuilder,I can find the data base in informix ,but when I load ,the fields do not show up!
      if you have used visual cafe before ,please let me know.