Discussions

EJB programming & troubleshooting: Transaction isolation level with Weblogic and Oracle

  1. It seems that using Oracle as the datastore for weblogic 5.1 has a basic floor.

    Let's say I want my session bean to do a very simple transaction - incrementing a field on an entity bean:
    1. Get a reference to an entity bean
    2. Read the value of its field
    3. Add 1 to that value
    4. Set the value of the entity bean field

    And I don't want some other transaction to come along and write to the entity bean while I'm doing step 3.

    According to Weblogic's documentation, "Oracle uses optomistic concurrency. As a consequence, even with a setting of TRANSACTION_SERIALIZABLE, Oracle does not detect serialization problems until commit time." It suggests I should check for this serialization exception and just try again! There doesn't seem to be a way to lock the entity bean from the time it is read until the time the transaction completes...

    One way around this is to move the workflow to the entity bean (e.g. add an 'increment' method to the entity interface). This would ensure serialized access to the entity bean, but leads to a fat entity bean with a constantly-changing interface.

    Is there a better way?
  2. Hmmm, shouldn't the application server be serializing request to this particular bean? I thought EJB 1.1 states that only one such instance of a bean can be accessed at a given time..