Results 1 to 2 of 2

Thread: Constainer Persistant EJB Prob

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    UK
    Posts
    222

    Constainer Persistant EJB Prob

    Hello

    I am writing some ejb's that should simply get some details and return them to a servlet that calls the functions.

    I have an entity bean called Book, which will hold the detail about a book.

    I have a session bean that i want to hold a vector or array of all the books in the system.

    How would i go about filling an array in my catalog with envery book entity?

    Hope someonce can help

    Cheers in advance

    Andy

  2. #2
    Member
    Join Date
    Nov 2001
    Location
    C2C
    Posts
    42
    in your session bean , add a method:

    public BookData[] getPBookList() throws RemoteException{

    try {

    BookHome home = HomeFactory.getBookHome();
    Enumeration enum = home.findAll();
    Vector vec = new Vector();

    if (enum != null) {
    while (enum.hasMoreElements()) {
    Object obj = enum.nextElement();
    Book ejb = (Book)PortableRemoteObject.narrow(obj,Book.class);
    BookData b = new BookData();
    b.Id = ejb.getBookId();
    b.name = ejb.getName();
    b.description = ejb.getDescription();
    p.price = ejb.getPrice();
    vec.addElement(p);
    }}
    BookData[] book_array = new BookData[vec.size()];
    vec.copyInto(book_array);
    return book_array;
    }
    catch (Exception e) {
    throw new RemoteException(e.getMessage());
    }}

    in your catalog (servlet?jsp?) component, call session bean's method. then you can get the array list of the books.
    Hai Kuo Ren Yu Yao. Tian Gao Ren Niao Fei.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width