0 Replies Latest reply on Feb 20, 2006 4:48 AM by Laszlo Graf

    one-to-many with XDoclet

    Laszlo Graf Newbie

      Hi,

      I am using JBoss-4.0.3.
      Shortly my scenarion:

      Table definitions:
      ----------------------------
      -- Categories
      ----------------------------
      id integer not null
      name varchar(50) not null --> books:category

      --------------------------------
      -- Books
      --------------------------------
      id integer not null
      title varchar(50) not null
      category integer not null


      The CMP Entity beans:

      /* Categories */
      ...
      /**
      * @ejb.interface-method
      *
      * @ejb.relation name="CategoriesBooks"
      * role-name="CategoryHasBooks"
      * target-ejb="BooksBean"
      * target-role-name="CategoryOfBook"
      *
      * @jboss.relation fk-column="category"
      * related-pk-field="id"
      *
      */
      public abstract Collection getBooks();
      /** @ejb.interface-method */
      public abstract void setBooks(Collection c);


      /* Books */
      ...
      /**
      * @ejb.interface-method
      *
      * @ejb.relation name="CategoriesBooks"
      * role-name="CategoryOfBook"
      * target-ejb="CategoriesBean"
      * target-role-name="CategoryHasBooks"
      * target-multiple="yes"
      *
      * @jboss.relation fk-column="id"
      * related-pk-field="id"
      *
      */
      public abstract Collection getCategories();
      /** @ejb.interface-method */
      public abstract void setCategories(Collection c);


      The output looks like this:

      [CategoriesSFBean] ejbCreate
      [CategoriesBean#findByPrimaryKey] Executing SQL: SELECT t0_CategoriesBean.id FROM categories t0_CategoriesBean WHERE t0_CategoriesBean.id=?
      [CategoriesBean] Executing SQL: SELECT name FROM categories WHERE (id=?)
      [CategoriesBean] load relation SQL: SELECT category FROM categoriesbean_books_booksbean_categories WHERE (id=?)

      But my goal is to see all the books that belong to one (specified) category. What should I modify to have something like this:

      SELECT id, title, category FROM categoriesbean_books_booksbean_categories WHERE (category=?)

      ?

      ----
      Laszlo