Calling Home.remove in ejbStore in Entity Bean

Discussions

EJB design: Calling Home.remove in ejbStore in Entity Bean

  1. Calling Home.remove in ejbStore in Entity Bean (3 messages)

    Hi

    I am using EJB 1.1 and BMP Entity Bean. Can I write following code in ejbStore.

    public void ejbStore() {
     String methodName = "ejbStore";
     logger.logMethodBegin(methodName);
     DealSheetAssociationInfoHome _home = null;
     DealSheetAssociationInfoKey _primaryKey = null;
     int _insAgrmntNo = 0;
     int _eventNo = 0;
     int _objectVerNo = 0;
     String _userId =null;
     ADMSAssociationChild _associationChild = null;
     try{
      if(METHOD_FLAG.equals("1")){
    return;
      }else{
     _home = (DealSheetAssociationInfoHome)
      myEntityCtx.getEJBHome();
    _primaryKey = (DealSheetAssociationInfoKey)
     myEntityCtx.getPrimaryKey();
      if(_home!=null && _primaryKey!=null){
     if(_primaryKey.getModuleName().equals(this.moduleName)){
     _insAgrmntNo = this.insAgrmntNo;
     _eventNo = this.eventNo;
     _objectVerNo = this.objectVerNo;
     _userId = this.userId;
     _associationChild = this.associationChild;
     _home.remove(_primaryKey);
     _home.create(_insAgrmntNo,_eventNo,_objectVerNo,_userId,_associationChild);
    }
       }
     }

    }catch(CreateException ce){
     logger.logFatal(methodName,ce.toString());
     throw new javax.ejb.EJBException(ce);
     }catch(RemoveException re){
     logger.logFatal(methodName,re.toString());
     throw new javax.ejb.EJBException(re);
    }catch(Exception e){
    logger.logFatal(methodName,e.toString());
    throw new javax.ejb.EJBException(e);
    }finally{
    logger.logMethodEnd(methodName);
    }
    }
  2. So far as I can tell, this is legal, although it is pretty strange.

    Why not just call ejbRemove() directly, rather than indirectly through the Home interface? And ditto for ejbCreate()? That would be more effecient, unless you are doing something strange with transactions.
  3. Hi Paul,

    You are not supposed to call "callbacks" methods directly othewise the conatiner will never come to know of entity creation or removal. If the pupose is only to use SQLs, they are better off in a private methods and used by other methods.

    Hemant
    www.pramati.com
  4. What is the harm if I go ahead with this approach? Where exactly there will be a trouble?