EntityBean updated values can't be read by JDBC


EJB programming & troubleshooting: EntityBean updated values can't be read by JDBC

  1. EntityBean updated values can't be read by JDBC (2 messages)


    I am developing an application in IBM Websphere server 5.0. And I've
    encountered a problem in using CMP Entity Bean.

    My case is that I have created a CMT seesion bean, called
    "myServiceBean", which has a method, called "testUpdate()" with tx
    setting as "Required", and its sample code is shown below. In the
    method, I tried to update a record using a CMP Entity Bean, Customer,
    and read the updated value using a SQL "SELECT ID, NAME FROM CUSTOMER
    WHERE ID = XXX" through JDBC. HOWEVER, I've found that the updated
    value can't be read by using JDBC, but can be read using the Entity
    Bean. You may think that the update is fialed so the updated value
    can't be read, but that is not true. Because after the transaction is
    end, I've checked the record's updated in the database.

    public void testUpdate() {
      System.out.println("Before update...");
      // Display the record before update using JDBC
      // Update the record's field "Name" using a CMP Entity Bean,
      // Customer, to "MAN2"
      Customer customer = customeHome.findByPrimaryKey(new

      System.out.println("After update...");
      // Display the updated value after updated using the Entity Bean
      System.out.println("By EJB, NAME = " + customer.getName());

      // Display the record after updated using JDBC

    private void showRecord(String _id) {
      // Get a connection from the Datasource through JNDI look-up
      Connnection con = getConnection();

      // Normal JDBC coding for executing "SELECT ID, NAME FROM CUSTOMER
    WHERE ID = _id"

      // Print out the result to the console.

    Before update...
    ID: 0001, NAME: JOJO
    After update...
    By EJB, NAME = MAN2
    ID: 0001, NAME: JOJO

    As you can see in the sample OUTPUT, the value of the "NAME" is same
    as before and after the update. I am wondering that why the entity
    bean updated value can't be read by using JDBC.

    Does any one could help me or give me some suggestion on this
    problem?? I really don't know that this problem is caused by my wrong
    server setting or any other things else.

    thx a lot.
  2. As u r updating the record and reading the same in same transaction.
    As u no the updated values use the same instead of reading agin from the database.

    Read the Record after completing the Transaction.
    Avoid UNCOMMITTED_READ, if you rollback the update what will happen to the data read by you.
  3. Mr. sibi jacobe,

    Thx for your reply first. But I am not quite understand what do you mean...
    As I have to do the update and then read the updated values back within the same transaction, I can't split the two steps into two transactions.

    For example,
    Now I'd like to perform a task as follow:
    1) Update some records in a table using Entity Bean
    2) Perform some validation using PLSQL which will get the updated values as data during the validation.
    3) If the validation is failed, then rollback the update in step (1).

    So if I read the records after completing the Transaction, then how can I rollback the update in step (1) when I am in step (3). Because of step (1) and step (2) and (3) are in different transactions.


    What I really want to do is that I have to read data updated through Entity Bean using JDBC in Websphere 5.0!

    As I know, the implementation in Weblogic, all the update on a Entity Bean will not effect until the end of a Transaction. So data updated through Entity Bean can't be "seen" using JDBC. But this behavier can be changed by setting an attribute "<delay-updates-until-end-of-tx>false</delay-updates-until-end-of-tx>" in the weblogic-ejb-jar.xml file.

    I am just wondering that does Websphere have same kind of setting or not?

    With many thx,