在你的ejbPostCreate中调用对R的setXXX

解决方案 »

  1.   

    怎么加呀,比方说在leagueBean中,有对teams的1-*关联,里面有
    public void ejbPostCreate (String id, String name, String sport) throws CreateException 
    我怎么在里面加R的setTeams(Collection teams)ejbPostCreate里面都没有Collection的实例,怎么加呀?
      

  2.   

    比如Account和xxx是1:m的关系,那么,在xxx中的写法是:public java.util.Date ejbCreate(String name,BigDecimal amount,AccountLocal account)
    throws javax.ejb.CreateException {
    setName(new java.util.Date());
    setAmount(transType);
    return null;
    }
    public void ejbPostCreate(String name,BigDecimal amount,AccountLocal account)
    throws javax.ejb.CreateException {
    setAccount(account);
    }
      

  3.   

    我想你应该对看看EJB的规范
    在EJB规范里明确写着:
    during ejbCreate the instance cannot acquire a reference to the associated
    entity object, and that reference is required by the set method.
    In the ejbPostCreate method, on the other hand, the instance may reference
    the associated entity object. Thus, a call to set can be made.
      

  4.   

    public void ejbPostCreate (String id, String name, String sport) throws CreateException 
    如果我setTeams(Connection teams),我这个teams从哪儿出??传过来的没有,我创建这个league就用String id, String name, String sport这三个参数,总不能每创建一次都传一个collection过去,也不可能呀..
    这样,我想照规范做也不行..
      

  5.   

    你现在是要用CMR ?!?!?!?!?!
    既然是CMR,你的CREATE方法怎么回是(String id, String name, String sport)?你的应该有一个ejbCreate(String id, String name, String sport, LeagueLocal league)方法和一个ejbPostCreate(String id, String name, String sport, LeagueLocal league)
    明白没?当你想create一个team的时候,写法是:
    LeagueLocal league=以某种方式得到一个league,比如findByPrimaryKey();
    TeamLocal team=teamHome.create("id","name","sport",league);
      

  6.   

    我创建一个League,还要放个本地接口进ejbCreate??
      

  7.   

    我创建一个League,还要放个本地接口进ejbCreate??
      

  8.   

    你好象一直没搞明白关系是什么对你的表来说,team关系到league,他们的关系是1:m
    所以,应该是创建一个team的时候,要把league放进去
    创建league的时候,和team没关系,明白没?
      

  9.   

    当你想create一个team的时候,写法是:
    LeagueLocal league=以某种方式得到一个league,比如findByPrimaryKey();
    TeamLocal team=teamHome.create("id","name","sport",league);
    **************************************************************
    我是否可以在ejbPostCreate()中“以某种方式得到一个league,比如findByPrimaryKey();
    ”,然后set CMR字段?
    我的关系是双向的,操作是不是一样的?