10 Replies Latest reply on Apr 29, 2003 3:20 PM by paulward

    Recursive CMR

    ddurst1

      Can someone show me an example of how to do a recursive CMR?

      Here is what I have but JBoss is barfing.

      <ejb-relation>
      <ejb-relation-name>Domain has parent domain</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>DomainEJB</ejb-relationship-role-name>
      Many
      <relationship-role-source><ejb-name>DomainEJB</ejb-name></relationship-role-source>
      <cmr-field>
      <cmr-field-name>subDomains</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>DomainEJB</ejb-relationship-role-name>
      One
      <relationship-role-source><ejb-name>DomainEJB</ejb-name></relationship-role-source>
      <cmr-field><cmr-field-name>parentDomain</cmr-field-name></cmr-field>
      </ejb-relationship-role>
      </ejb-relation>

        • 1. Re: Recursive CMR
          ddurst1

          Does anyone actually use this forum to reply, or do people just post and never get any replies?

          • 2. Re: Recursive CMR
            darranl

            No people generaly do reply if they understand the question and have an answer to it.

            • 3. Re: Recursive CMR
              thammoud

              In my experience the CMP forum is the worst when it comes to getting responses. The best is the cluster forum.

              • 4. Re: Recursive CMR
                raja05

                Here is what i have as a developer-manager relationship in the same table.
                Employee {
                empid,
                age,
                blah blah,
                managerid references empid
                }

                ejb-jar.xml
                <ejb-relation >
                <ejb-relation-name>developer-manager</ejb-relation-name>

                <ejb-relationship-role >
                <ejb-relationship-role-name>developer-assigned-to-manager</ejb-relationship-role-name>
                Many
                <relationship-role-source >
                <ejb-name>Employee</ejb-name>
                </relationship-role-source>
                <cmr-field >
                <cmr-field-name>manager</cmr-field-name>
                </cmr-field>
                </ejb-relationship-role>

                <ejb-relationship-role >
                <ejb-relationship-role-name>manager-has-employees</ejb-relationship-role-name>
                One
                <relationship-role-source >
                <ejb-name>Employee</ejb-name>
                </relationship-role-source>
                </ejb-relationship-role>

                </ejb-relation>


                jbosscmp-jdbc.xml

                <ejb-relation>
                <ejb-relation-name>developer-manager</ejb-relation-name>

                <foreign-key-mapping/>

                <ejb-relationship-role>
                <ejb-relationship-role-name>developer-assigned-to-manager</ejb-relationship-role-name>
                <fk-constraint>true</fk-constraint>
                <key-fields/>
                </ejb-relationship-role>
                <ejb-relationship-role>
                <ejb-relationship-role-name>manager-has-employees</ejb-relationship-role-name>
                <key-fields>
                <key-field>
                <field-name>empID</field-name>
                <column-name>manager</column-name>
                </key-field>
                </key-fields>
                </ejb-relationship-role>
                </ejb-relation>

                Hope this is what you are looking for

                -Raj

                • 5. Re: Recursive CMR
                  jonmartin

                  I take it your recursive relationship is a tree-like structure. I use JDeveloper to develop my ejb's, and it works just fine for stuff like this. I struggled quite a lot defining recursive cmr manually a year ago, and finally gave up. Didn't get a reasonable answer on any forum or newsgroup either. Well, anyway, here is my ejb-jar.xml stuff:

                  <ejb-relation>
                  <ejb-relation-name>ThemeHierarchy</ejb-relation-name>
                  <ejb-relationship-role>
                  <ejb-relationship-role-name>ThemeHasChildren</ejb-relationship-role-name>
                  One
                  <relationship-role-source>
                  <ejb-name>EntTheme</ejb-name>
                  </relationship-role-source>
                  <cmr-field>
                  <cmr-field-name>children</cmr-field-name>
                  <cmr-field-type>java.util.Collection</cmr-field-type>
                  </cmr-field>
                  </ejb-relationship-role>
                  <ejb-relationship-role>
                  <ejb-relationship-role-name>ThemeHasParent</ejb-relationship-role-name>
                  Many
                  <cascade-delete/>
                  <relationship-role-source>
                  <ejb-name>EntTheme</ejb-name>
                  </relationship-role-source>
                  <cmr-field>
                  <cmr-field-name>parent</cmr-field-name>
                  </cmr-field>
                  </ejb-relationship-role>
                  </ejb-relation>

                  While I'm editing this in the tiny little textbox editor I can't really say how this differ from your xml, maybe I'lls ee it after I've posted :-) And I'm running on 3.0.6, 3.0.7 and 3.2.0. It'd also be useful to see the actual error message you get if this doesn't help.

                  • 6. Re: Recursive CMR
                    jonmartin

                    Does it work without the cmr-field-type?

                    • 7. Re: Recursive CMR
                      jonmartin

                      I try to reply, but I don't see my postings? Is this forum moderated or something?

                      • 8. Re: Recursive CMR
                        jonmartin

                        Here is my ejb-jar.xml that works for me. Generally JDeveloper does the job of defining different cmr-stuff well, at least I use it without problems.

                        It's not needed to define anything in any jboss-specific configuration files, and tables are created where needed by jboss.

                        <ejb-relation>
                        <ejb-relation-name>ThemeHierarchy</ejb-relation-name>
                        <ejb-relationship-role>
                        <ejb-relationship-role-name>ThemeHasChildren</ejb-relationship-role-name>
                        One
                        <relationship-role-source>
                        <ejb-name>EntTheme</ejb-name>
                        </relationship-role-source>
                        <cmr-field>
                        <cmr-field-name>children</cmr-field-name>
                        <cmr-field-type>java.util.Collection</cmr-field-type>
                        </cmr-field>
                        </ejb-relationship-role>
                        <ejb-relationship-role>
                        <ejb-relationship-role-name>ThemeHasParent</ejb-relationship-role-name>
                        Many
                        <cascade-delete/>
                        <relationship-role-source>
                        <ejb-name>EntTheme</ejb-name>
                        </relationship-role-source>
                        <cmr-field>
                        <cmr-field-name>parent</cmr-field-name>
                        </cmr-field>
                        </ejb-relationship-role>
                        </ejb-relation>

                        • 9. Re: Recursive CMR
                          paulward

                          Someone already posted a copy of their descriptor, but I thought it might be helpful if someone posted the way one might go about this using the xdoclet tags to do this. Below are the methods that relate to a self-reference of Member to Group

                          /**
                          * Get the groups that this destination is a member of
                          *
                          * @ejb.interface-method
                          *
                          * @ejb.relation name="Destination-Destination"
                          * role-name="member-has-groups"
                          *
                          * @jboss.relation-table table-name="GROUP_MEMBERS"
                          * create-table="true"
                          * remove-table="false"
                          * pk-constraint="true"
                          *
                          * @jboss.method-attributes read-only="true"
                          * @jboss.relation fk-constraint="true"
                          * fk-column="GROUP_ID"
                          * related-pk-field="iD"
                          *
                          **/
                          public abstract Set getGroups();

                          /**
                          * Set the groups that this destination is a member of
                          *
                          * @param groups The new list of groups.
                          *
                          **/
                          public abstract void setGroups(Set groups);

                          /**
                          * Get the destinations that are members of this group
                          *
                          * @ejb.interface-method
                          *
                          * @ejb.relation name="Destination-Destination"
                          * role-name="group-has-members"
                          *
                          * @jboss.relation-table table-name="GROUP_MEMBERS"
                          * create-table="false"
                          * remove-table="false"
                          *
                          * @jboss.method-attributes read-only="true"
                          * @jboss.relation fk-constraint="true"
                          * fk-column="MEMBER_ID"
                          * related-pk-field="iD"
                          *
                          **/
                          public abstract Set getMembers();

                          /**
                          * Set the list of destinations that are members of this group
                          *
                          * @param members The new list of members.
                          *
                          **/
                          public abstract void setMembers(Set members);

                          • 10. Re: Recursive CMR
                            paulward

                            Someone already posted a copy of their descriptor, but I thought it might be helpful if someone posted the way one might go about this using the xdoclet tags to do this. Below are the methods that relate to a self-reference of Member to Group

                            /**
                            * Get the groups that this destination is a member of
                            *
                            * @ejb.interface-method
                            *
                            * @ejb.relation name="Destination-Destination"
                            * role-name="member-has-groups"
                            *
                            * @jboss.relation-table table-name="GROUP_MEMBERS"
                            * create-table="true"
                            * remove-table="false"
                            * pk-constraint="true"
                            *
                            * @jboss.method-attributes read-only="true"
                            * @jboss.relation fk-constraint="true"
                            * fk-column="GROUP_ID"
                            * related-pk-field="iD"
                            *
                            **/
                            public abstract Set getGroups();

                            /**
                            * Set the groups that this destination is a member of
                            *
                            * @param groups The new list of groups.
                            *
                            **/
                            public abstract void setGroups(Set groups);

                            /**
                            * Get the destinations that are members of this group
                            *
                            * @ejb.interface-method
                            *
                            * @ejb.relation name="Destination-Destination"
                            * role-name="group-has-members"
                            *
                            * @jboss.relation-table table-name="GROUP_MEMBERS"
                            * create-table="false"
                            * remove-table="false"
                            *
                            * @jboss.method-attributes read-only="true"
                            * @jboss.relation fk-constraint="true"
                            * fk-column="MEMBER_ID"
                            * related-pk-field="iD"
                            *
                            **/
                            public abstract Set getMembers();

                            /**
                            * Set the list of destinations that are members of this group
                            *
                            * @param members The new list of members.
                            *
                            **/
                            public abstract void setMembers(Set members);