1 Reply Latest reply on Feb 16, 2005 4:17 PM by lafr

    XDoclet tags for CMR foreign key

    gioele

      What is the correc XDoclet way to specify this two tables in two Entity beans?

      CREATE TABLE Family (
      id INTEGER,
      data VARCHAR,
      PRIMARY KEY (id)
      )

      CREATE TABLE Person (
      id INTEGER,
      name VARCHAR,
      family INTEGER,
      PRIMARY KEY (id),
      FOREIGN KEY (family) Family (id)
      )

      The first one is a simple FamilyBean without any CMR relation, the second one is created from PersonBean

      /**
       * @ejb.bean name="Person"
       * type="CMP"
       * cmp-version="2.x"
       * view-type="local"
       * primkey-field="id"
       */
      public abstract class PersonBean implements EntityBean {
       /* ... omitted normal CMP methods */
      
       /**
       * Getter for CMR Relationship
       *
       * @ejb.interface-method view-type="local"
       * @ejb.relation name="Person-is-in-Family"
       * role-name="Person"
       * target-ejb="Family"
       * target-role-name="Family"
       * target-multiple="no"
       */
       public abstract Integer getFamily();
       /* setFamily omitted */
      }

      My doubts are:

      • Should I use "Integer" or "FamilyLocal" as return type of getFamily?
      • Should I add the @jboss.target-relation tag to the relationship?
      • even if I add @jboss.target-relation, the Person table has not a foreign key. What should I use to get it?


        • 1. Re: XDoclet tags for CMR foreign key
          lafr

          Although this is not a xdoclet forum I'll send an answer.
          For such a n-1 relation we use this (replace mbi_festa with person and mbi_feber with family for your need):
          /**
          * @ejb.interface-method
          * @ejb.relation
          * name="MbiFesta-MbiFeberBereichNr"
          * role-name="n-mbi_festa-1-mbi_feber_bereich_nr"
          * multiple="no"
          * target-multiple="yes"
          * target-cascade-delete="no"
          * target-ejb="MbiFeber"
          * target-role-name="1-mbi_feber_bereich_nr-n-mbi_festa"
          * @jboss.relation
          * related-pk-field="bereichNr"
          * fk-column="bereich_nr"
          * @jboss.relation-read-ahead strategy="on-find"
          */
          public abstract biz.mbisoftware.fn.ejb.entity.MbiFeberLocal getMbiFeberBereichNr();
          /**
          * @ejb.interface-method
          */
          public abstract void setMbiFeberBereichNr(
          final biz.mbisoftware.fn.ejb.entity.MbiFeberLocal mbiFeber );