EJB m:n relationship in JBoss + Xdoclet javacode 9085791

EJB m:n relationship in JBoss + Xdoclet

In the Java code, we continue as usual:

  • The BookBean is created as usual, the CMR authors field is set in the ejbPostCreate() method
  • The same holds for the AuthorBean

Finally, for the sake of completeness, we illustrate how to access the authors from the book.

    private BookDTO getBookData(BibliographyLocal bib)
    {
        BookDTO dto = new BookDTO();

        // Book specifics
        Collection authors = bib.getBook().getAuthorOReditors();
        AuthorDTO[] authorsOReditors = new AuthorDTO[authors.size()];
        Iterator iterator = authors.iterator();

        int i = 0;
        while (iterator.hasNext())
        {
            authorsOReditors[i] = getAuthorDTO(
                (AuthorLocal) iterator.next());
            i++;
        }

        ...

(The Book Data Transfer Object BookDTO transfers the Book data retrieved from the Book entity bean (via a Session Facade) to the Web tier (or Java client)).

Via the BookLocal object, we have access to the collection of AuthorLocal objects, as shown above. Using the an interator we can access the individual Author objects, from which we can invoke the getters to retrieve the author information.

5 Comments

  1. Pingback: Credit Monitoring Services April 28, 2007
  2. Pingback: Student Credit Cards April 26, 2007
  3. Pingback: File Cabinets April 24, 2007
  4. Pingback: Furniture Guys April 22, 2007
  5. John Lim January 3, 2006
  6. Zeger Hendrikse June 2, 2005
  7. stephen smithstone June 1, 2005
  8. Zeger Hendrikse May 18, 2005
  9. Natalia Camargo May 18, 2005