1 Reply Latest reply on Dec 11, 2001 1:43 PM by gabi

    IllegalStateException: removing bean lock and it has tx set!

    gabi Newbie

      Hi,
      I am using jboss 2.4.4 with jdk1.4 beta3
      i have session(stateless) bean calling entity bean(BMP)calling DAO implementation class(doing the actual sql things).
      i am calling getAllX in the session bean that calls findAllX in the entity bean that calls daoFindAllX in the DAO class.
      the entity gets the DAO implementation class by calling the DAOFactory.getDAO() method.
      in the constructor of the DAO class i lookup once for the datasource.
      my problem is that now i want to work with 2 shcemas that have the same table (no conflict with primary key) so i remove the allocation of the datasource from the constructor and put it in a new method. so the instantiation of the DAO take now 2 steps:
      1. daoClass = DAOFactory.getDAO();
      2. daoClass.setDataSource(JNDIDataSourceName);

      this aproach cause an exception: "java.lang.IllegalStateException: removing bean lock and it has tx set!" and i don't figure why?

      my classes:
      public class daoImpl implements daoInterface {
      private transient Connection dbConnection = null;
      private transient DataSource datasource = null;

      public void setDataSource(String datasourceName)
      throws GlobalRuntimeException {
      try {
      datasource = (DataSource) new InitialContext().lookup("java:comp/env/jdbc/" + datasourceName);
      } catch (NamingException ne) {
      cat.error(ne);
      throw new GlobalRuntimeException(ne);
      }
      }
      }

      public class MyEntityEJB implements EntityBean {
      public Collection ejbFindAllX() throws FinderException {
      try{
      getDAO();
      return daoClass.daoFindAllX();
      } catch (NotFoundException nfe) {
      throw new FinderException(nfe.getMessage());
      } catch (GlobalRuntimeException gre) {
      throw new EJBException(gre);
      }
      }

      private void getDAO() {
      if(daoClass == null) {
      daoClass = DAOFactory.getDAO();
      }
      String tempName = this.entityContext.getCallerPrincipal().getName();
      String datasourceName = tempName.substring(0, tempName.indexOf(":"));
      daoClass.setDataSource(datasourceName );
      }
      }

      public class MySessionEJB implements SessionBean {
      public ArrayList getAllX() throws FinderException {
      try{
      lookupHomeEntity();
      Collection col =
      (Collection) PortableRemoteObject.narrow(entityHome.findAllX(), Collection.class);
      Iterator it = col.iterator();
      ArrayList array = new ArrayList();
      while (it.hasNext()) {
      entityRemote eRemote = (entityRemote ) it.next();
      // at this point the exception in thrown
      // at - eRemote.Data();
      array.add(eRemote.Data());
      }
      return array;
      } catch (RemoteException re) {
      cat.error(re);
      throw new EJBException(re);
      }
      }
      }

      thanks!!!