Calling Home.remove in ejbStore in Entity Bean


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

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


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

    public void ejbStore() {
     String methodName = "ejbStore";
     DealSheetAssociationInfoHome _home = null;
     DealSheetAssociationInfoKey _primaryKey = null;
     int _insAgrmntNo = 0;
     int _eventNo = 0;
     int _objectVerNo = 0;
     String _userId =null;
     ADMSAssociationChild _associationChild = null;
     _home = (DealSheetAssociationInfoHome)
    _primaryKey = (DealSheetAssociationInfoKey)
      if(_home!=null && _primaryKey!=null){
     _insAgrmntNo = this.insAgrmntNo;
     _eventNo = this.eventNo;
     _objectVerNo = this.objectVerNo;
     _userId = this.userId;
     _associationChild = this.associationChild;

    }catch(CreateException ce){
     throw new javax.ejb.EJBException(ce);
     }catch(RemoveException re){
     throw new javax.ejb.EJBException(re);
    }catch(Exception e){
    throw new javax.ejb.EJBException(e);
  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.

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