2 Replies Latest reply on Jul 24, 2002 9:06 AM by deepaksumani

    Help Needed !! Getting javax.transaction.xa.XAException

    deepaksumani

      Hi folks,
      i need a help regarding the problem listed down.
      when a single user access the application deployed on JBoss 2.4.4_Tomcate-4.0.1 it works fine
      if number of users increases more then one then the exception is thrown "javax.transaction.xa.XAException" mainly in ejbFindByXXX methods .
      The transcation attributes of all ejbFindByXXX is Required
      It's urgent

      cheers
      Deepak
      [17:05:37,625,TxCapsule] XAException: tx=XidImpl [FormatId=257, GlobalId=TESTMACH//219, BranchQual=] errorCode=XAER_PROTO
      javax.transaction.xa.XAException
      at org.opentools.minerva.jdbc.xa.wrapper.XAResourceImpl.end(XAResourceImpl.java:124)
      at org.jboss.tm.TxCapsule.endResource(TxCapsule.java:1130)
      at org.jboss.tm.TxCapsule.delistResource(TxCapsule.java:524)
      at org.jboss.tm.TransactionImpl.delistResource(TransactionImpl.java:99)
      at org.jboss.pool.jdbc.xa.XAConnectionFactory$2.closeConnection(Unknown Source)
      at org.jboss.pool.jdbc.xa.XAConnectionFactory$2.connectionClosed(Unknown Source)
      at org.opentools.minerva.jdbc.xa.wrapper.XAConnectionImpl.clientConnectionClosed(XAConnectionImpl.java:126)
      at org.opentools.minerva.jdbc.xa.wrapper.XAClientConnection.close(XAClientConnection.java:250)
      at com.ewt.trs.datalayer.login.LoginBean.cleanup(Unknown Source)
      at com.ewt.trs.datalayer.login.LoginBean.ejbFindByPrimaryKey(Unknown Source)
      at sun.reflect.GeneratedMethodAccessor36.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at org.jboss.ejb.plugins.BMPPersistenceManager.callFinderMethod(BMPPersistenceManager.java:503)
      at org.jboss.ejb.plugins.BMPPersistenceManager.findEntity(BMPPersistenceManager.java:231)
      at org.jboss.ejb.EntityContainer.find(EntityContainer.java:610)
      at sun.reflect.GeneratedMethodAccessor30.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.java:859)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchronizationInterceptor.java:234)
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:147)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:97)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxInterceptorCMT.java:142)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:347)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:86)
      at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:102)
      at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:103)
      at org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:421)
      at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invokeHome(JRMPContainerInvoker.java:456)
      at org.jboss.ejb.plugins.jrmp.interfaces.HomeProxy.invokeHome(HomeProxy.java:237)
      at org.jboss.ejb.plugins.jrmp.interfaces.HomeProxy.invoke(HomeProxy.java:182)
      at $Proxy82.findByPrimaryKey(Unknown Source)
      at com.ewt.trs.bussinesslayer.loginService.LoginServiceBean.getLoginDetail(Unknown Source)
      at sun.reflect.GeneratedMethodAccessor35.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:542)
      at org.jboss.ejb.plugins.TxInterceptorBMT.invoke(TxInterceptorBMT.java:299)
      at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:82)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:127)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:170)
      at org.jboss.ejb.StatelessSessionContainer.invoke(StatelessSessionContainer.java:286)
      at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invoke(JRMPContainerInvoker.java:410)
      at sun.reflect.GeneratedMethodAccessor32.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
      at sun.rmi.transport.Transport$1.run(Transport.java:148)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
      at java.lang.Thread.run(Thread.java:536)
      [17:05:37,718,Default] Returning User's LoginID

        • 1. Re: Help Needed !! Getting javax.transaction.xa.XAException
          garyg

          My guess (as the XAER_PROTO API page shows) is that you're not properly grabbing the context when beans are being manipulated and a method/routine is run ... causing the error.

          Make sure you're setEntityContext and unsetEntityContext are doing there jobs.

          • 2. Re: Help Needed !! Getting javax.transaction.xa.XAException
            deepaksumani

            hi ,
            thanxs for ur help , well what i feel that there is no problem with the set/unset Entity Context Method .
            i am pasting a bean code and let me know if it requries any changes.

            Any sort help help be appricated
            thanxs
            Deepak


            ***********************************************

            /**
            * Sets the EntityContext for the EJBean.
            *
            * @param EntityContext ctx
            * @exception java.rmi.RemoteException
            */
            public void setEntityContext(EntityContext ctx)
            throws RemoteException
            {
            log("setEntityContext called of GroupUserBean");
            this.ctx = ctx;
            iGroupUser = new GroupUserData();
            jndi_Name = getJNDIname();
            }

            /**
            * Unsets the EntityContext for the EJBean.
            * @exception java.rmi.RemoteException
            */
            public void unsetEntityContext()
            throws RemoteException
            {
            log("unsetEntityContext called of GroupUserBean");
            this.ctx = null;
            }

            public void ejbActivate()
            throws RemoteException
            {
            log("ejbActivate called of GroupUserBean");
            }

            public void ejbPassivate()
            throws RemoteException
            {
            log("ejbPassivate called of GroupUserBean");
            }

            public void ejbLoad()throws RemoteException
            {
            log("ejbLoad: called of GroupUserBean");

            Connection con = null;
            PreparedStatement ps = null;

            GroupUserPK pk = (GroupUserPK) ctx.getPrimaryKey();
            try {
            con = getConnection();
            ps = con.prepareStatement("select * from TR_GROUP_USER where GROUP_ID = ? and USER_ID = ?");
            ps.setLong(1,pk.getGroupsID());
            ps.setLong(2,pk.getUserID());
            ps.executeQuery();
            ResultSet rs = ps.getResultSet();

            if (rs.next())
            {
            iGroupUser.setGroupsID(rs.getLong(1));
            iGroupUser.setUserID(rs.getLong(2));
            }
            else
            {
            String error = "ejbLoad: GroupUserBean (" + pk.getGroupsID() + pk.getUserID() + ") not found";
            log(error);
            throw new NoSuchEntityException (error);
            }
            }
            catch (SQLException sqe)
            {
            log("SQLException: " + sqe);
            throw new EJBException(sqe);
            }
            finally
            {
            cleanup(con, ps);
            }
            }

            /**
            * Stores the EJBean in the persistent storage.
            *
            * @exception javax.ejb.NoSuchEntityException
            * if the bean is not found in the database
            * @exception javax.ejb.EJBException
            * if there is a communications or systems failure
            * @exception java.rmi.RemoteException
            */
            public void ejbStore()throws RemoteException
            {
            log("ejbStore called of GroupUserBean");

            Connection con = null;
            PreparedStatement ps = null;

            try {
            GroupUserPK pk = (GroupUserPK) ctx.getPrimaryKey();
            con = getConnection();
            ps = con.prepareStatement("UPDATE TR_GROUP_USER set GROUP_ID=?,USER_ID=?"
            + "where GROUP_ID = ? and USER_ID = ?");
            ps.setLong(1,iGroupUser.groupsID());
            ps.setLong(2,iGroupUser.userID());
            ps.setLong(3,pk.getGroupsID());
            ps.setLong(4,pk.getUserID());
            if (!(ps.executeUpdate() > 0))
            {
            String error = "ejbStore: GroupUserBean (" + pk.getGroupsID() +pk.getUserID() + ") not updated";
            log(error);
            throw new NoSuchEntityException (error);
            }
            }
            catch(SQLException sqe)
            {
            log("SQLException: " + sqe);
            throw new EJBException (sqe);
            }
            finally
            {
            cleanup(con, ps);
            }
            }

            /**
            * This method takes the same arguments as the create method.
            * The container calls it after ejbCreate() completes.
            * Use this method for any special processing needed after
            * the bean is created, but before it becomes available
            * to the client. Leave empty if no special processing
            * is needed.
            *
            * @param long _groupID
            * @param long _userID
            *
            * @exception java.rmi.RemoteException
            */
            public void ejbPostCreate(long _group,long _userID) throws CreateException,RemoteException,NamingException,FinderException
            {
            log("ejbPostCreate called of GroupUserBean");
            }

            /**
            * This method corresponds to the create method in the home interface
            * "GroupUserHome.java".
            * The parameter sets of the two methods are identical. When the client calls
            * GroupUserHome.create(), the container allocates an instance
            * of this bean and calls GroupUserBean.ejbCreate().
            *
            * For bean-managed persistence, ejbCreate() returns
            * a primary key, unlike the case of container-managed
            * persistence, where it returns a void.
            *
            *
            * @param long _groupsID
            * @param long _userID
            *
            * @return GroupUserPK
            *
            * @exception javax.ejb.CreateException
            * if there is a problem creating the bean
            * @exception javax.ejb.DuplicateKeyException
            * if a create is attempted using a Primary Key
            * already in the database
            * @exception javax.ejb.EJBException
            * if there is a communications or systems failure
            * @exception java.rmi.RemoteException
            *
            * @exception javax.ejb.NamingException
            */
            public GroupUserPK ejbCreate(long _groupsID,long _userID)
            throws CreateException,RemoteException,NamingException,FinderException
            {
            log("GroupUserBean.ejbCreate()");

            Connection con = null;
            PreparedStatement ps = null;

            try {
            con = getConnection();
            ps = con.prepareStatement("INSERT INTO TR_GROUP_USER VALUES (?,?)");
            ps.setLong(1,_groupsID);
            ps.setLong(2,_userID);
            if (ps.executeUpdate() != 1)
            {
            String error = "JDBC did not create any row";
            log(error);
            throw new CreateException (error);
            }
            else
            {
            iGroupUser.setGroupsID(_groupsID);
            iGroupUser.setUserID(_userID);
            }

            return new GroupUserPK(_groupsID,_userID);
            }
            catch (SQLException sqe)
            {
            // Check to see if this SQLException is due to a unique constraint
            // violation on our database table . If so, throw a
            // DuplicateKeyException else throw a CreateException.
            try {
            ejbFindByPrimaryKey(_groupsID,_userID);
            }
            catch(ObjectNotFoundException onfe)
            {
            String error = "SQLException: " + sqe;
            log(error);
            throw new CreateException (error);
            }
            String error = "An GroupUserBean already exists in the database with Composite Primary Key " + _groupsID + _userID;
            log(error);
            throw new DuplicateKeyException(error);
            }
            finally
            {
            cleanup(con, ps);
            }
            }

            /**
            * Deletes the EJBean from the persistent storage.
            *
            * @exception javax.ejb.NoSuchEntityException
            * if the bean is not found in the database
            * @exception javax.ejb.EJBException
            * if there is a communications or systems failure
            * @exception java.rmi.RemoteException
            *
            * @exception java.rmi.RemoveException
            */
            public void ejbRemove()throws RemoteException,RemoveException
            {
            log("ejbRemove called of GroupUserBean");
            // we need to get the primary key from the Context because
            // it is possible to do a remove right after a find, and
            // ejbLoad may not have been called.
            Connection con = null;
            PreparedStatement ps = null;
            try
            {
            con = getConnection();
            GroupUserPK pk = (GroupUserPK)ctx.getPrimaryKey();
            String message = "GroupUserBean (" + pk.getGroupsID() + pk.getUserID() + " remove ";
            log(message);


            ps = con.prepareStatement("DELETE FROM TR_GROUP_USER where GROUP_ID = ? AND USER_ID=?");
            ps.setLong(1, pk.getGroupsID());
            ps.setLong(2, pk.getUserID());
            if (!(ps.executeUpdate() > 0))
            {
            String error = "GroupUserBean (" + pk.getGroupsID() + pk.getUserID() + " not found";
            log(error);
            throw new NoSuchEntityException (error);
            }
            }
            catch (SQLException sqe)
            {
            log("SQLException: " + sqe);
            throw new EJBException (sqe);
            }
            finally
            {
            cleanup(con, ps);
            }
            }


            /**
            * Attempts to find the EJBean with a given Primary Key from
            * the persistent storage.
            *
            * @param long _groupsID
            * @param long _userID
            *
            * @return GroupUserPK
            * @exception javax.ejb.ObjectNotFoundException
            * thrown if the EJBean cannot be found
            * @exception javax.ejb.EJBException
            * if there is a communications or systems failure
            * @exception java.rmi.RemoteException
            */
            public GroupUserPK ejbFindByPrimaryKey(long _groupsID,long _userID)throws RemoteException,FinderException
            {
            log("ejbFindByPrimaryKey (" + _groupsID + "," + _userID + ")");

            Connection con = null;
            PreparedStatement ps = null;
            try {
            con = getConnection();
            ps = con.prepareStatement("SELECT * FROM TR_GROUP_USER WHERE GROUP_ID = ? AND USER_ID = ? ");
            ps.setLong(1, _groupsID);
            ps.setLong(2, _userID);
            ps.executeQuery();
            ResultSet rs = ps.getResultSet();
            if (rs.next())
            {
            iGroupUser.setGroupsID(rs.getLong(1));
            iGroupUser.setUserID(rs.getLong(2));
            }
            else
            {
            String error = "ejbFindByPrimaryKey: GroupUserBean (" + _groupsID + _userID + ") not found";
            log(error);

            }
            }
            catch (SQLException sqe)
            {
            log("SQLException: " + sqe);
            throw new EJBException (sqe);
            }
            finally
            {
            cleanup(con, ps);
            }

            log("ejbFindByPrimaryKey (" + _groupsID + ","+ _userID + ") found");
            return new GroupUserPK(_groupsID ,_userID);
            }

            /**
            * Attempts to find a Long groupID for a given userID
            *
            * @param long _userID
            *
            * @return Groups
            * @exception javax.ejb.FinderException
            * if there is an error finding the bean
            * @exception java.rmi.RemoteException
            * if there is a communications or systems failure
            */
            public GroupUserPK ejbFindByUserGroupID(long _userID)
            throws FinderException, RemoteException
            {
            log("ejbFindByUserGroupID("+ _userID + ")called of GroupUserBean");
            log("test");


            Connection con = null;
            PreparedStatement ps = null;
            long groupID = 0;
            try {
            con = getConnection();
            ps = con.prepareStatement("select Group_ID from TR_GROUP_USER where User_ID = ?");
            ps.setLong(1,_userID);
            ps.executeQuery();

            ResultSet rs = ps.getResultSet();
            if (rs.next())
            {
            groupID = rs.getLong(1);
            log(groupID + " GroupID");
            }
            else
            {
            String error = "ejbFindByGroupUserID: GroupUserBean (" + _userID + ") not found";
            log(error);
            }

            } catch (SQLException sqe)
            {
            log("SQLException: " + sqe);
            throw new EJBException (sqe);
            }
            finally
            {
            cleanup(con, ps);
            }
            log("ejbFindByUserGroupID found");
            return new GroupUserPK(groupID,_userID);
            }


            /**
            * Attempts to find the all users in group.
            *
            * @param long _groupID
            *
            * @return Collection
            * @exception javax.ejb.FinderException
            * if there is an error finding the bean
            * @exception java.rmi.RemoteException
            * if there is a communications or systems failure
            */
            public Collection ejbFindByGroupUserID(long _groupID)throws FinderException, RemoteException
            {
            log("ejbFindByGroupUserID(" + _groupID + ") called of GroupUserBean");

            Connection con = null;
            PreparedStatement ps = null;
            Vector user = new Vector();
            try {
            con = getConnection();
            ps = con.prepareStatement("SELECT USER_ID FROM TR_GROUP_USER WHERE GROUP_ID =?");
            ps.setLong(1,_groupID);
            ps.executeQuery();
            ResultSet rs = ps.getResultSet();
            while(rs.next())
            {
            log("User Id is"+ rs.getLong(1));
            user.addElement( new GroupUserPK(_groupID,rs.getLong(1)));
            }
            } catch (SQLException sqe)
            {
            log("SQLException: " + sqe);
            throw new EJBException (sqe);
            }
            finally
            {
            cleanup(con, ps);
            }
            log("ejbFindByGroupUserID found");
            return user;
            }

            /**
            * For printing the output on the console.
            */
            private void log(String s)
            {
            if (VERBOSE) System.out.println(s);
            }

            /**
            * Gets current connection to the connection pool.
            *
            * @return Connection
            * @exception javax.ejb.EJBException
            * if there is a communications or systems failure
            * @exception java.sql.SQLException
            * if there is a SQL query Exception
            */
            private Connection getConnection()
            throws SQLException
            {
            InitialContext initCtx = null;
            try {
            initCtx = new InitialContext();
            DataSource ds= (javax.sql.DataSource)initCtx.lookup("java:/jdbc/TimeReportDB");
            return ds.getConnection();
            }
            catch(NamingException ne)
            {
            log("Failed to lookup JDBC Datasource. Please double check that");
            throw new EJBException(ne);
            }
            finally
            {
            try {
            if(initCtx != null) initCtx.close();
            }
            catch(NamingException ne)
            {
            log("Error closing context: " + ne);
            throw new EJBException(ne);
            }
            }
            }

            /**
            * For cleaning up the Connection.
            */
            private void cleanup(Connection con, PreparedStatement ps)
            {
            try {
            if (ps != null) ps.close();
            } catch (Exception e)
            {
            log("Error closing PreparedStatement: "+e);
            throw new EJBException (e);
            }
            try {
            if (con != null) con.close();
            } catch (Exception e)
            {
            log("Error closing Connection: " + e);
            throw new EJBException (e);
            }
            }

            /**
            * This Function helps to look the jndi-path from the config file
            *
            * @param String invokingFile
            * @param String key
            *
            * @return String
            *
            */
            private String getJNDIname()
            {
            try
            {
            Context ctxJndi = new InitialContext();
            Context envoirnment = (Context)ctxJndi.lookup("java:/comp/env");
            return (String)envoirnment.lookup("JNDI PATH");
            }
            catch(Exception e)
            {
            log(e.getMessage() + "Resource is missing");
            return null;
            }
            }

            }