home.create(categoryId,category,categoryDescription);
放到
CategoryESMHome home=(CategoryESMHome)context.lookup("CategoryESMHome");
语句前看看

解决方案 »

  1.   

    将他们的位置调换?home还没有赋值啊!
      

  2.   

    public void createCategory(String categoryId, String category,
                                 String categoryDescription)throws Exception {
        CategoryESMHome home=(CategoryESMHome)context.lookup("CategoryESMHome");
       try{
        CategoryESM categoryESM=home.findByPrimaryKey(categoryId);
       }catch(Exception ex){
        home.create(categoryId,category,categoryDescription);
          }  }
    上面那位兄弟,这样为什么不行啊?它应该出现什么异常,怎么捕捉这个异常呢?谢谢你
      

  3.   

    catch(Exception ex){
        home.create(categoryId,category,categoryDescription);
          }
    是不是应该改为
    catch(FindException ex){
       try{
        home.create(categoryId,category,categoryDescription);
    }
    catch(Exception e){
    }
          }因为,如果是因其它异常产生的Exception如果被catch住的话,由于已经存在一个categoryId
    你再新建一个categoryId,这样主键会产生冲突。:)
    再者create语句也会产生Exception的啊。