添加记录可以调用实体bean的create方法,同时向create方法传送主键参数,比如下面这个应该对你有所帮助:AUser auser = null;
    /**@todo Complete this method*/
    try
   {
      Context context= new InitialContext();
      Object ref=context.lookup("AUser");
      AUserHome auserHome=(AUserHome)PortableRemoteObject.narrow(ref,AUserHome.class);
      System.out.println("Insert a user whose id is:"+id);
      auser=auserHome.create(id);
      auser.setPassword(password);   }
   catch(Exception ex){
   System.out.println("Exception in adding!"+ex);
   }

解决方案 »

  1.   

    楼上的兄弟,“auser.setPassword(password);”是什么意思啊?
      另外,如果数据库表除主键外都允许为空的话可以生成只有主键不为空的记录,但如果存在不允许为空的字段的话,是添加不了的,即记录插不进去。
      

  2.   

    如果是这样你就要修改ejbcreate(.....)方法,将不为空的参数写进去,然后传值调用就可以了
      

  3.   

    新建一条是用 auser=auserHome.create(id);     也可以自己写一个create方法更新一条是先找到这条记录
               auser=auserHome.findByPrimaryKey(id);
                然后再 auser.setPassword(password);从而更新password字段