0 Replies Latest reply on Mar 6, 2002 4:09 AM by Alexey Loubyansky

    "required" transactions in 3.0.0beta2

    Alexey Loubyansky Master

      Hello.

      I wrote an entity bean Section with local interfaces and a session bean Catalog with remote interfaces to access it. All methods in the entity and session beans are marked as "Required". In the session bean I have a method addSection(SectionData data) that calls create on the entity's local home.
      I've made some tests:
      1. adding 'throw new EJBException("thrown by jalex")' just before 'return null' in the entity beans's local home create method causes the transaction to be rolled back and datasource is untouched, as it was supposed.
      2. but adding 'throw new EJBException("thrown by jalex")' in the session bean's method addSection(SectionData data) after the call to bean's local home create method doesn't properly rolls back the transaction.

      This is entity bean's local home create method:
      public String ejbCreate(SectionData data) {
      setSectionId(data.getSectionId());
      setSectionData(data);
      return null;
      }

      This is session bean's addSection(SectionData data) method:
      public void addSection(SectionData data) {
      try {
      SectionLocalHome homeLocal = SectionUtil.getLocalHome();
      String pk = data.getSectionId();
      if(pk == null) {
      pk = PrimaryKeyGenerator.getUUID(data);
      data.setSectionId(pk);
      }
      SectionLocal local = homeLocal.create(data);
      System.out.println("CatalogBean: section added: " + local.getSectionData().toString());
      throw new EJBException("thrown by jalex");
      } catch(Exception e) {
      throw new EJBException(e);
      }
      }

      And the log is:
      2002-03-05 14:11:32,885 DEBUG [org.jboss.ejb.plugins.EnterpriseContextCachePolicy] Resized cache for bean Document: old capacity = 1000000, new capacity = 50
      2002-03-05 14:11:40,326 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.Section] Create: pk=1
      2002-03-05 14:11:40,326 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.Section] Executing SQL: SELECT COUNT(*) FROM Section WHERE sectionId=?
      2002-03-05 14:11:40,366 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.Section] Executing SQL: INSERT INTO Section (sectionId, parentId, name, creationDate, lastModifiedDate, docLifetime) VALUES (?, ?, ?, ?, ?, ?)
      2002-03-05 14:11:40,376 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.Section] Create: Rows affected = 1
      2002-03-05 14:11:40,416 ERROR [org.jboss.ejb.GlobalTxEntityMap] Store failed on entity: 1
      javax.ejb.EJBException: Error getting application tx data map.
      Embedded Exception
      Already marked for rollback
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.getApplicationTxDataMap(JDBCStoreManager.java:207)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.synchronizeRelationData(JDBCStoreManager.java:434)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.storeEntity(JDBCStoreManager.java:430)
      at org.jboss.ejb.plugins.CMPPersistenceManager.storeEntity(CMPPersistenceManager.java:428)
      at org.jboss.ejb.EntityContainer.storeEntity(EntityContainer.java:676)
      at org.jboss.ejb.GlobalTxEntityMap.syncEntities(GlobalTxEntityMap.java:177)
      at org.jboss.ejb.GlobalTxEntityMap$GlobalTxEntityMapCleanup.beforeCompletion(GlobalTxEntityMap.java:315)
      at org.jboss.tm.TxCapsule.doBeforeCompletion(TxCapsule.java:1317)
      at org.jboss.tm.TxCapsule.rollback(TxCapsule.java:430)
      at org.jboss.tm.TransactionImpl.rollback(TransactionImpl.java:88)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:180)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:61)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:127)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
      at org.jboss.ejb.StatelessSessionContainer.invoke(StatelessSessionContainer.java:308)
      at org.jboss.ejb.Container.invoke(Container.java:668)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1555)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
      at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:363)
      at java.lang.reflect.Method.invoke(Native Method)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:241)
      at sun.rmi.transport.Transport$1.run(Transport.java:152)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:148)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:465)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:706)
      at java.lang.Thread.run(Thread.java:484)
      javax.transaction.RollbackException: Already marked for rollback
      at org.jboss.tm.TxCapsule.registerSynchronization(TxCapsule.java:729)
      at org.jboss.tm.TransactionImpl.registerSynchronization(TransactionImpl.java:133)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.getApplicationTxDataMap(JDBCStoreManager.java:196)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.synchronizeRelationData(JDBCStoreManager.java:434)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.storeEntity(JDBCStoreManager.java:430)
      at org.jboss.ejb.plugins.CMPPersistenceManager.storeEntity(CMPPersistenceManager.java:428)
      at org.jboss.ejb.EntityContainer.storeEntity(EntityContainer.java:676)
      at org.jboss.ejb.GlobalTxEntityMap.syncEntities(GlobalTxEntityMap.java:177)
      at org.jboss.ejb.GlobalTxEntityMap$GlobalTxEntityMapCleanup.beforeCompletion(GlobalTxEntityMap.java:315)
      at org.jboss.tm.TxCapsule.doBeforeCompletion(TxCapsule.java:1317)
      at org.jboss.tm.TxCapsule.rollback(TxCapsule.java:430)
      at org.jboss.tm.TransactionImpl.rollback(TransactionImpl.java:88)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:180)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:61)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:127)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
      at org.jboss.ejb.StatelessSessionContainer.invoke(StatelessSessionContainer.java:308)
      at org.jboss.ejb.Container.invoke(Container.java:668)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1555)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
      at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:363)
      at java.lang.reflect.Method.invoke(Native Method)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:241)
      at sun.rmi.transport.Transport$1.run(Transport.java:152)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:148)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:465)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:706)
      at java.lang.Thread.run(Thread.java:484)

      Why is it so? I expected the datasource to be untouched but it contains inserted data.

      alex