3 Replies Latest reply on Sep 27, 2002 11:57 AM by humps

    TransactionRolledbackException using CMR !!

    pol.leleux Newbie

      Hello all,

      I have a table with a non-mandatory foreign key, i.e. it can contain either the id of a linked object or -1 if there is no linked object. I defined a CMR relationship (one-to-many), when I try to fetch the linked object (and there is no linked object but I don't know it yet), I get the following :

      15:07:47,899 ERROR [LogInterceptor] TransactionRolledbackException, causedBy:
      javax.ejb.NoSuchEntityException: Entity not found: primaryKey=[.-1.]
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadEntityCommand.execute(JDBCLoad
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadEntityCommand.execute(JDBCLoad
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.loadEntity(JDBCStoreM
      at org.jboss.ejb.plugins.CMPPersistenceManager.loadEntity(CMPPersistence
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.load
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntityS
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invo
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstance
      at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockIntercep
      at org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreation
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep

      I was expecting it would return either 'null' or generate an exception that I could catch but I was not expecting it would rollback the current transaction !! (which destroys all I've done in it till now)

      Is there any kind of solution ?

      Thanks in advance...

        • 1. Re: TransactionRolledbackException using CMR !!
          humps Newbie

          'non mandatory Fk' means the relationship does not exist when there is no value in the Fk column. It is the first time I've heard someone using -1 to represent a null!!! I take it you're integrating with a existing DB that has been used like that? Otherwise I cannot imagine someone using -1 provided the Fk is null-able.

          You can either map the Fk as CMP field and do a manual get method which would be very ugly, but might just work. Or use null to represent what really is a null.

          • 2. Re: TransactionRolledbackException using CMR !!
            pol.leleux Newbie

            you are right, I'm integrating with an existing database where "null" relationships are represented with an id set to -1 (valid id values are >= 0).

            I was just wondering why JBoss was rollbacking the current transaction when it couldn't find the related object ! It doesn't give you any chance to recover from that kind of problem...

            Anyway, converting the database to set the field 'nullable' and set a 'null' value where -1 is found would solve the problem...

            Thanks taking time answering...

            • 3. Re: TransactionRolledbackException using CMR !!
              humps Newbie

              It does depend on your transaction boundaries and code implementation. If you're catching the NoSuchEntity exception and make it carry on in your code, sure, JBoss won't roll back. Or you'll have to decide where to put your set transaction in the descriptors depending on
              a) where the transaction was started (session bean?)
              b) should that method support transaction at all?
              c) or simply try catch finderExp, instanceof NoSuchEntity and say you're ok to carry on without finding something in your code.

              good luck