Discussions

EJB programming & troubleshooting: the problem about the AccessBean in VisualAge

  1. the problem about the AccessBean in VisualAge (3 messages)

    hi, when I create a CMP Entity Bean in VA3.5 Enterprise Edition, I do it successfully, but after I create an AccessBean for it, I create a Servlet to use the accessBean,there is one problem:
    TestAccessBean test = new TestAccessBean("test");
    test.getTestName();
    ----it catch an NullPointerException.

    but if i use following codes, it succeed.
    TestAccessBean test = new TestAccessBean("test");
    (TestHome) home = (TestHome) test.getHome();
    Test obj = home.findByPrimaryKey("test");
    obj.getTestName();

    ----it succeed.

    The official file(EJB.PDF in the VA) says that after we create an AccessBean, we can use its getter and setter methods directly, but now i have to use these methods after I create the EJBObject, what is the reason?

    thanks in advance.

    bruce

  2. Here is how I created my access bean in a servlet:

    AccountAccessBean accountAccessBean = new
          AccountAccessBean();
    accountAccessBean.setInit_key(new
          AccountBaseKey("123456"));
    String title = accountAccessBean.getAccountTitle();

    First I instantiate the access bean then I need to set the primary key. Now I can use the getters and setters. Let me know if this helps. There is another way to instantiate the bean but I find this way easier.

    Dan
  3. Firstly, thanks a lot for you useful answer.
    now I have tried it again;

    UnitCodeKey key = new UnitCodeKey("001");
    UnitCodeAccessBean ab = new UnitCodeAccessBean(key);
    System.out.println(ab.getUnit_name());

    it it successful, but I do this several days ago, it failed--return the NullPointerException. what is the reason?

    I try what u said too, but it failed-- return the DuplicateException, it seems that when i use the setInit_argUnit_code("001"), the accessbean create a new record in the database, but i have inserted it before, so I catch the DuplicateException.

    anyway, thanks u again.


    bruce

  4. hi bruce

    Can u tell me how to use visualage fro java 3.5 to deploy beans in websphere
    vinod