0 Replies Latest reply on Nov 22, 2002 6:17 PM by John Freeborg

    TransactionRolledBackLocalException not propagating correctl

    John Freeborg Newbie


      - SQL Server 2000 w/ SP2
      - NetDirect JSQLConnect 3.27 JDBC drivers
      - JBoss 3.0.3 w/ Tomcat 4.1.12
      - Windows 2000 w/ SP3
      - Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
      - Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)
      - EJB 2.0 CMP entity bean with local interfaces

      I've got a junit test case which makes sure that the container properly handles attempts to create new entity beans which violate a unique index on the underlying table.

      If the unique index is only on a field of the entity bean (i.e. just a db column - no keys), my create() method on the local home interface throws a javax.ejb.CreateException
      with a nice root exception identifying the index problem. Great!

      However, if the unique index on my table includes the foreign key which is used in the CMP CMR relation, the container gets confused.

      Specifically I'm seeing the new row get created after ejbCreate(). The index is not violated yet because the CMR foreign key column is null at this point. After the ejbPostCreate() is when the index is violated as JBossCMP attempts to update the row. In this case the create()
      method on the local home interface throws a java.lang.reflect.UndeclaredThrowableException which appears in violation of the EJB 2.0 spec in section "18.3.1 Exceptions from a session or entity bean’s business methods"

      In the JBoss server log I see things start out well, but the EJBException that is shown here is not propagated correctly back through the local home interface create() method.

      2002-11-22 16:10:44,415 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreEntityCommand.ZipCode] Executing SQL: UPDATE ZipCode SET StateID=? WHERE ZipCodeID=?
      2002-11-22 16:10:44,425 TRACE [org.jboss.resource.connectionmanager.LocalTxConnectionManager$LocalConnectionEventListener] connectionClosed called
      2002-11-22 16:10:44,425 TRACE [org.jboss.resource.connectionmanager.CachedConnectionManager] unregistering connection from org.jboss.resource.connectionmanager.LocalTxConnectionManager@78529d, object: org.jboss.resource.adapter.jdbc.local.LocalConnection@fffa61, key: org.jboss.resource.connectionmanager.CachedConnectionManager$IdentityWrapper@b1fea4
      2002-11-22 16:10:44,425 TRACE [org.jboss.resource.connectionmanager.LocalTxConnectionManager$LocalConnectionEventListener] unregisterConnection: 0
      2002-11-22 16:10:44,425 TRACE [org.jboss.resource.connectionmanager.CachedConnectionManager] popped object: org.jboss.resource.connectionmanager.CachedConnectionManager$IdentityWrapper@b1fea4
      2002-11-22 16:10:44,425 ERROR [org.jboss.ejb.GlobalTxEntityMap] Store failed on entity: 152
      javax.ejb.EJBException: Store failed; CausedByException is:
      Violation of UNIQUE KEY constraint 'IX_ZipCode'. Cannot insert duplicate key in object 'ZipCode'.
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreEntityCommand.execute(JDBCStoreEntityCommand.java:94)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.storeEntity(JDBCStoreManager.java:589)
      at org.jboss.ejb.plugins.CMPPersistenceManager.storeEntity(CMPPersistenceManager.java:458)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.storeEntity(CachedConnectionInterceptor.java:388)
      at org.jboss.ejb.EntityContainer.storeEntity(EntityContainer.java:708)
      at org.jboss.ejb.GlobalTxEntityMap.syncEntities(GlobalTxEntityMap.java:99)
      at org.jboss.ejb.GlobalTxEntityMap$GlobalTxEntityMapCleanup.beforeCompletion(GlobalTxEntityMap.java:168)
      at org.jboss.tm.TxCapsule.doBeforeCompletion(TxCapsule.java:1394)
      at org.jboss.tm.TxCapsule.commit(TxCapsule.java:364)
      at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:73)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:201)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:52)
      at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:105)
      at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:129)
      at org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:487)
      at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invokeHome(BaseLocalContainerInvoker.java:230)
      at org.jboss.ejb.plugins.local.LocalHomeProxy.invoke(LocalHomeProxy.java:110)
      at $Proxy98.create(Unknown Source)
      at com.softswitch.igrid.ejb.entity.test.TestZipCodeBean.testCreate(TestZipCodeBean.java:65)