0 Replies Latest reply on Apr 27, 2012 5:33 AM by hipa

    Remote EJB call from one server to another vs transactions

    hipa

      There are two JBoss 7.1.1.Final servers. The first one contains BeanA

       

      @Stateless
      @Remote(IBeanA.class)
      public class BeanA implements IBeanA {
        @PersistenceContext
        private EntityManager em;
      
        public void test() {
          em.createNativeQuery("insert into A(value) values (0)").executeUpdate();
        }
      }
      

       

      The second one contains BeanB

       

      @Stateless
      @LocalBean
      public class BeanB {
        @PersistenceContext
        private EntityManager em;
      
        public void test() {
          em.createNativeQuery("insert into A(value) values(1)").executeUpdate();
      
          try {
            Hashtable props = new HashTable();
            props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
            InitialContext ctx = new InitialContext(props);
            IBeanA beanA = (IBeanA) ctx.lookup("ejb:app/ejb/BeanA!IBeanA");
            beanA.test();
          } catch (NamingException e) {
            throw new RuntimeException(e);
          }
      
          em.createNativeQuery("insert into A(value) values(2)").executeUpdate();
        }
      }
      

       

      After BeanB.test() call there are only two records in the A table with values 1 and 2, so the transaction on server 1 was not committed. It never commits nor rollbacks even if I stop server 1. It's strange but if I wrap remote calls in BeanB into a separate transaction or to a method with no transaction support, all works as expected. I think it's definitely a bug.