0 Replies Latest reply on Jul 16, 2002 3:24 PM by Albrecht Schänzel

    Unexpected data model on one to one uni-directional relation

    Albrecht Schänzel Newbie

      Hi,

      In my application I want to implement the following object model but the generated data model
      looks strange to me. Here are the facts:

      I have 2 classes:

      - Animal
      - AccessType (e.g. birth, additional buy, embryo transfer etc.)

      An Animal has got three 1:1 uni-directional relationships:

      1. Target class: Animal, attribute: femaleParent
      2. Target class: Animal, attribute: maleParent
      3. Target class: AccessType, attribute: accessType

      The interface of the bean looks like this:
      ------------------------------------------
      public abstract String getObjectId();
      public abstract void setObjectId(String _objectId);

      public abstract String getName();
      public abstract void setName(String _name);

      public abstract java.sql.Date getDateOfBirth();
      public abstract void setDateOfBirth(java.sql.Date _dateOfBirth);

      public abstract Character getSex();
      public abstract void setSex(Character _sex);

      public abstract Animal getFemaleParent();
      public abstract void setFemaleParent(Animal _femaleParent);

      public abstract Animal getMaleParent();
      public abstract void setMaleParent(Animal _maleParent);

      public abstract AccessType getAccessType();
      public abstract void setAccessType(AccessType _accessType);

      public abstract Timestamp getLastUpdate();
      public abstract void setLastUpdate(Timestamp _lastUpate);


      The ejb-jar.xml looks like this:
      --------------------------------
      ...

      <ejb-relation>
      <ejb-relation-name>Female-Parent</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>hasFemaleParent</ejb-relationship-role-name>
      One<
      <relationship-role-source>
      <ejb-name>Animal</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>femaleParent</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>femaleParentOfAnimal</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>Animal</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      </ejb-relation>
      <ejb-relation>
      <ejb-relation-name>Male-Parent</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>hasMaleParent</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>Animal</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>maleParent</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>maleParentOfAnimal</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>Animal</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      </ejb-relation>

      <ejb-relation>
      <ejb-relation-name>Animal-AccessType</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>animalHasAccessType</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>Animal</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>accessType</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>accessTypeOfAnimal</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>AccessType</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      </ejb-relation>

      ...

      The jbosscmp-jdbc.xml looks like this:
      --------------------------------------
      ...
      <enterprise-beans>

      <ejb-name>Animal</ejb-name>
      <table-name>ANIMAL</table-name>
      <cmp-field>
      <field-name>objectId</field-name>
      <column-name>OBJECT_ID</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(20)</sql-type>
      </cmp-field>
      <cmp-field>
      <field-name>name</field-name>
      <column-name>NAME</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(20)</sql-type>
      </cmp-field>
      <cmp-field>
      <field-name>dateOfBirth</field-name>
      <column-name>DATE_OF_BIRTH</column-name>
      <jdbc-type>DATE</jdbc-type>
      <sql-type>DATE</sql-type>
      </cmp-field>
      <cmp-field>
      <field-name>lastUpdate</field-name>
      <column-name>LAST_UPDATE</column-name>
      <jdbc-type>TIMESTAMP</jdbc-type>
      <sql-type>TIMESTAMP</sql-type>
      </cmp-field>


      <ejb-name>AccessType</ejb-name>
      <table-name>ACCESS_TYPE</table-name>
      <cmp-field>
      <field-name>objectId</field-name>
      <column-name>OBJECT_ID</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(20)</sql-type>
      </cmp-field>
      <cmp-field>
      <field-name>type</field-name>
      <column-name>TYPE</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(20)</sql-type>
      </cmp-field>
      <cmp-field>
      <field-name>description</field-name>
      <column-name>DESCRIPTION</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(80)</sql-type>
      </cmp-field>
      <cmp-field>
      <field-name>lastUpdate</field-name>
      <column-name>LAST_UPDATE</column-name>
      <jdbc-type>TIMESTAMP</jdbc-type>
      <sql-type>TIMESTAMP</sql-type>
      </cmp-field>

      </enterprise-beans>

      <ejb-relation>
      <ejb-relation-name>Female-Parent</ejb-relation-name>
      <foreign-key-mapping>
      <ejb-relationship-role>
      <ejb-relationship-role-name>hasFemaleParent</ejb-relationship-role-name>
      <foreign-key-fields>
      <foreign-key-field>
      <field-name>objectId</field-name>
      <column-name>FK_FEMALE_PARENT</column-name>
      </foreign-key-field>
      </foreign-key-fields>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>femaleParentOfAnimal</ejb-relationship-role-name>
      <foreign-key-fields/>
      </ejb-relationship-role>
      </foreign-key-mapping>
      </ejb-relation>
      <ejb-relation>
      <ejb-relation-name>Male-parent</ejb-relation-name>
      <foreign-key-mapping>
      <ejb-relationship-role>
      <ejb-relationship-role-name>hasMaleParent</ejb-relationship-role-name>
      <foreign-key-fields>
      <foreign-key-field>
      <field-name>objectId</field-name>
      <column-name>FK_MALE_PARENT</column-name>
      </foreign-key-field>
      </foreign-key-fields>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>maleParentOfAnimal</ejb-relationship-role-name>
      <foreign-key-fields/>
      </ejb-relationship-role>
      </foreign-key-mapping>
      </ejb-relation>
      <ejb-relation>
      <ejb-relation-name>Animal-AccessType</ejb-relation-name>
      <foreign-key-mapping>
      <ejb-relationship-role>
      <ejb-relationship-role-name>animalHasAccessType</ejb-relationship-role-name>
      <foreign-key-fields>
      <foreign-key-field>
      <field-name>objectId</field-name>
      <column-name>FK_ACCESS_TYPE</column-name>
      </foreign-key-field>
      </foreign-key-fields>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>accessTypeOfAnimal</ejb-relationship-role-name>
      <foreign-key-fields/>
      </ejb-relationship-role>
      </foreign-key-mapping>
      </ejb-relation>

      ...

      The generated tables looks like this:
      -------------------------------------

      1. animal
      - Animal_maleParent varchar(20)
      - Animal_femaleParent varchar(20)
      - maleParent varchar(20)
      - accessType varchar(20)
      - femaleParent varchar(20)
      - LAST_UPDATE timestamp(14)
      - DATE_OF_BIRTH date
      - OBJECT_ID varchar(20)

      2. acccess_type
      - Animal_accessType varchar(20)
      - LAST_UPDATE timestamp(14)
      - DESCRIPTION varchar(80)
      - TYPE varchar(20)
      - OBJECT_ID varchar(20)

      I expected the following data model:
      ------------------------------------

      1. ANIMAL
      - FK_FEMALE_PARENT varchar(20)
      - FK_ACCESS_TYPE varchar(20)
      - FK_MALE_PARENT varchar(20)
      - LAST_UPDATE timestamp(14)
      - DATE_OF_BIRTH date
      - OBJECT_ID varchar(20)

      2. ACCESS_TYPE
      - LAST_UPDATE timestamp(14)
      - DESCRIPTION varchar(80)
      - TYPE varchar(20)
      - OBJECT_ID varchar(20)

      What did I do wrong? It would be greatly appreciate if somebody could help me.
      Thank you very much in advance.

      Kindest regards
      Albrecht