2 Replies Latest reply on Nov 8, 2001 10:33 PM by cincaipatron

    cannot invoke remove() on stateful session bean

    cincaipatron

      Hi, I got trouble with stateful session bean, I'm using mySql, jboss 2.4.1. I got error when I
      invoke remove() method (end a session) from client. I included some code from my bean, even if
      I let ejbPassivate() and ejbActivate() blank still product the same result.

      Here's the exception:
      ====================
      [SynchCatalog] TRANSACTION ROLLBACK EXCEPTION:null
      Embedded Exception
      Unable to deregister with TransactionManager: java.lang.IllegalArgumentException: xaRes not enlisted; nested exception is:
      javax.ejb.EJBException: null
      Embedded Exception
      Unable to deregister with TransactionManager: java.lang.IllegalArgumentException: xaRes not enlisted
      [SynchCatalog] java.lang.RuntimeException: Unable to deregister with TransactionManager: java.lang.IllegalArgumentException: xaRes not enlisted
      [SynchCatalog] at org.jboss.pool.jdbc.xa.XAConnectionFactory$2.closeConnection(XAConnectionFactory.java:110)
      [SynchCatalog] at org.jboss.pool.jdbc.xa.XAConnectionFactory$2.connectionClosed(XAConnectionFactory.java:89)
      [SynchCatalog] at org.jboss.pool.jdbc.xa.wrapper.XAConnectionImpl.clientConnectionClosed(XAConnectionImpl.java:134)
      [SynchCatalog] at org.jboss.pool.jdbc.xa.wrapper.XAClientConnection.close(XAClientConnection.java:250)
      [SynchCatalog] at matashop.product.ejb.SynchCatalogBean.ejbRemove(SynchCatalogBean.java:417)
      [SynchCatalog] at java.lang.reflect.Method.invoke(Native Method)
      [SynchCatalog] at org.jboss.ejb.plugins.StatefulSessionFilePersistenceManager.removeSession(StatefulSessionFilePersistenceManager.java:327)
      [SynchCatalog] at org.jboss.ejb.StatefulSessionContainer.remove(StatefulSessionContainer.java:349)
      [SynchCatalog] at java.lang.reflect.Method.invoke(Native Method)
      ...
      ...
      etc
      ====================

      Here's my bean:

      public class MyStatefulBean implements SessionBean {
          private transient Connection con;

          public void ejbCreate() throws CreateException, RemoteException {
              try
              {
                  InitialContext jndiContext = new InitialContext();
                  DataSource dataSource = (DataSource)jndiContext.lookup(DATASOURCE);
                  con = dataSource.getConnection();
              }
              catch (SQLException e) { throw new CreateException("Error acquiring dbase connection"); }
              catch (NamingException e) { throw new CreateException("Error initializing jndiContext"); }
          }

          public void ejbRemove() throws RemoteException {
              if (con != null)
                  try
                  {
                      con.close();
                      con = null;
                  }
                  catch(SQLException e) { throw new RemoteException("Error closing connection. " + e.getMessage()); }
          }

          public void ejbActivate() throws EJBException {
              try
              {
                  InitialContext jndiContext = new InitialContext();
                  DataSource dataSource = (DataSource)jndiContext.lookup(DATASOURCE);
                  con = dataSource.getConnection();
              }
              catch (SQLException e) { throw new EJBException("Error acquiring dbase connection"); }
              catch (NamingException e) { throw new EJBException("Error initializing jndiContext"); }
          }

          public void ejbPassivate() throws EJBException {
              if (con != null)
                  try
                  {
                      con.close();
                      con = null;
                  }
                  catch(SQLException e) { throw new RemoteException("Error closing connection. " + e.getMessage()); }
          }

        • 1. Re: cannot invoke remove() on stateful session bean
          cincaipatron

          If I change <trans-attribute> in ejb-jar.xml to Never or Supports
          for that stateful-bean, invocation of con.close() in ejbRemove() success.

          So far, I understand that if I use trans-attribute Never, the
          stateful-bean will execute method without transaction
          even if the client is in transaction context.
          For Supports, if client is in transaction context, statefull will also in transaction
          context, and if client isn't in transaction context, stateful bean execute
          without transaction.

          It seems that if stateful-bean is in transaction context, invocation of con.close()
          will fail, but why? Could somebody please enlight me?

          • 2. Re: cannot invoke remove() on stateful session bean
            cincaipatron

            Hmm, is this jboss bug? here's a quote from tutorial
            [pre]The EJB container invokes the ejbCreate method at the beginning of a session bean's
            life cycle and invokes the ejbRemove method at the end. To retain a connection
            for the lifetime of a session bean, you connect to the database in ejbCreate and
            disconnect in ejbRemove. If the session bean is stateful, you must also
            connect in ejbActivate and disconnect in ejbPassivate. A stateful session bean
            requires these additional calls because the EJB container may passivate
            the bean during its lifetime.
            [pre]