3 Replies Latest reply on Aug 19, 2004 3:36 AM by sbrbot

    Container Managed Relationships query

    rajs1

      I have a simple many~to~many relationship.

      Person and Org have a many to many (bi-directional) relationship. In the DB this is managed by a Person_Org_List table.

      Primary key for Person table is person_id.
      Primary key for Org table is org_id.
      Obviously primary key for Person_Org_List table is person_id & org_id.


      Person
      |
      |
      ^
      Person_Org_List
      v
      |
      |
      Org


      However Person_Org_List (apart from the 2 foreign keys person_id and org_id) has an additonal (non-primary) field called designation.

      I got JBoss (3.2.5) to manage this many-to-many relationship with

      <relation-table-mapping>

      However, when I add an org to a person I notice that only the org_id and person_id appear in Person_Org_List table in the DB (which is expected).

      But this means I can never get hold of the designation column in that table.

      Does this mean that I must create a PersonOrgList entity and map Person entity as a one-to-many with PersonOrgList entity and similarly Org entity as a one-to-many with PersonOrgList entity?

      Cheers
      -raj

        • 1. Re: Container Managed Relationships query
          invisiblemage

          how do you think the java code to access this field would look like?

          • 2. Re: Container Managed Relationships query
            rajs1

            Well, short answer is "I don't know".

            Long answer is, at the moment I map Person-to-Organisation with a many-to-many (bidirectional) relationship.

            I have a BMP Entity called PersonOrgRole that manages the Person_Organisation_List table.

            I have JUnit tested the interactions between these three (entities) so far (to death) and it all seems to hang together.

            The posting was to see if there were any other (better?) design ideas.

            The design is done in UML and the exported XMI is passed through AndroMDA using the EJB cartridge.

            This allows me to try various design options.

            Cheers
            -raj

            • 3. Re: Container Managed Relationships query
              sbrbot

              When using CMP beans for Person and Org EJBs, where you create many-to-many CMRs, you're NOT able to use columns from cross-table Person_Org_List. Unfortunatelly, EJB specification (framework) haven't yet evolved til this stage to be able to use this attributes. For now, cross table is used by many-to-many CMRs. So only PersID and OrgID are used under the hood by the container.

              If you want to be able to use columns from cross-table then you have forget of many-to-many CMR and introduce additional EJB for cross-table where you will create one-to-many CMR between PersonEJB and PersonOrgEJB and another many-to-one CMR between PersonOrgEJB and OrgEJB. Only in this case you're able to reach attributes from cross table from PersonOrgEJB. I know that this complicates the application a bit but that's how it is.