2 Replies Latest reply on Nov 6, 2006 11:50 AM by jaysperk

    TransactionRolledBackLocalException accessing entity bean re

    jaysperk

      I am getting an exception TransactionRolledBackLocalException caused by NoSuchObjectLocalException: Entity not found
      under the following scenario:

      Using BMT.
      Commit Option A.

      Entities
      Customer
      Account
      Customer has one to many relationship with accounts.

      Sequence of events:
      Start Transaction
      Create a customer entity (PK - 400)
      Commit

      Start Transaction (T1 - Start)
      Create an account entity (PK - 1)
      Add account (PK - 1) to customer entity (PK - 400, custaccts CMR)

      Start Transaction (T2 - Start, T1 - suspended)
      Get customer entity (PK - 400)
      Create account entity (PK - 100)
      Add account (PK - 100) to customer (PK - 400, custaccts CMR)
      Rollback transaction (T2 - End, T1 - activated)

      Create account (PK - 1000)
      Get accounts for customer(PK - 400) - contains 2 entities (should contain 1 account (PK - 1))
      Go through list of accounts and access field - get exception above because one of the created entities does not exist because of a rollback.

      Is this the expected behavior? Or would you expect the CMR method that gets the accounts for a customer to return only valid entities? Or does this have something to do with my commit option? Can I avoid having my transaction rolled back when I find the stale entity?

        • 1. Re: TransactionRolledBackLocalException accessing entity bea
          jaysperk

          After alot of research, I have come to the following conclusion. Performing a rollback does not rollback any changes made to a CMR relationship altered in concurrent transactions. The changes made to the database seem to be rolled back, but the entity that contains the CMR relationship will still contain the association.

          Entity of type A has one to many relationship with Entity of type B

          Start Transaction 1
          Load Entity A1
          Create Entity B1
          Add Entity B1 to Entity A1 CMR relationship
          Suspend Transaction 1
          Start Transaction 2
          Create Entity B2
          Add Entity B2 to Entity A1
          Rollback Transaction 2
          Resume Transaction 1
          Call CMR relationship to get B entities from A1
          Returns RelationSet with 2 Entities
          Get NoSuchObjectLocalException when accesing CMP field from entity B2 found in the returned RelationSet because the creation of B2 was rolled back but the relationship between A1 and B2 still existed in memory.

          Conclusion:
          The CMR relationship is not being cleaned up when Transaction 2 is rolled back. Transaction 1
          will get a RelationSet that contains a reference to the rolled back entity B2.

          If you use the per transaction entity instance cache (to jboss.xml below)
          <instance-cache>org.jboss.ejb.plugins.PerTxEntityInstanceCache</instance-cache>
          You will avoid the problem because each transaction is working on a separate instance
          of the entity. This won't work for us however, because you also would not see commits
          that occurred in transaction 2, within transaction 1.

          Is anyone familiar with this problem? Or does anyone know of a workaround?

          • 2. Re: TransactionRolledBackLocalException accessing entity bea
            jaysperk

            One more tidbit - this may be related to the following bug:
            http://jira.jboss.com/jira/browse/EJBTHREE-605

            However, I am not sure about that because it is using EJB 3 where were are using EJB 2.