4 Replies Latest reply on Aug 3, 2002 11:46 AM by Russell Simpkins

    How to map One-To-Many Relationship

    Tung Dang Novice

      I have the following database structure:

      table product:
      - productid char(10)
      - description varchar(100)

      table detail:
      - id char(10)
      - prodid char(10)
      - description varchar(100)

      One product can have many details. The field prodid in the table detail is the foreign key of product.

      I have 2 beans: ProductBean and DetailBean. In the ProductBean I have the get/set methods for relationship like this:

      public abstract Collection getDetails();
      public abstract void setDetails(Collection details);

      Since I have the unidirectional relationship, I do not have the get/set method for relationship in the DetailBean. I declared ralationship in ejb-jar.xml as well.

      In ejb-jar.xml, I do not declare the field prodid of the table.

      Here is my mapping in the jbosscmp-jdbc.xml




      I could successfully deployed, but while running the client, I got the following error:


      The code of the client looks like this:
      ProductHome home = getHome();
      Product r = home.findByPrimaryKey("pr1");
      Collection details = r.getDetails();
      My question is: Is my mapping correct? What does the error mean?