1 Reply Latest reply on Oct 13, 2003 4:48 AM by Darran Lofthouse

    CMR: can't make many-2-one relation works !

    fdal Newbie

      Hi there,

      I got a problem setting up a simple many-2-one relation.
      I got a User (Utilisateur in French) Entity CMP and a Profil (Profil in French) Entity CMP.
      User got a idProfil cmp field as a foreign key to the Profil bean. As a user only have 1 profil and a profil got many users (Utilisateur), I got a many-2-one relation. Of course Profil doesn't see Utilisateur (users).
      Here is my ejb-jar.xml that i got for those two entity and the relation between them two:

      Utilisateur:

      <display-name>Utilisateur</display-name>
      <ejb-name>Utilisateur</ejb-name>
      <local-home>com.steria.agape.objet.UtilisateurHome</local-home>
      com.steria.agape.objet.Utilisateur
      <ejb-class>com.steria.agape.objet.UtilisateurBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>com.steria.agape.objet.primarykey.UtilisateurPK</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>Utilisateur</abstract-schema-name>
      <cmp-field>
      <field-name>idUser</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>codeProfil</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>login</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>password</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>derniereCnx</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>actif</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>nom</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>prenom</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>description</field-name>
      </cmp-field>


      Profil:

      <display-name>Profil</display-name>
      <ejb-name>Profil</ejb-name>
      <local-home>com.steria.agape.objet.ProfilHome</local-home>
      com.steria.agape.objet.Profil
      <ejb-class>com.steria.agape.objet.ProfilBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>com.steria.agape.objet.primarykey.ProfilPK</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>Profil</abstract-schema-name>
      <cmp-field>
      <field-name>codeProfil</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>libelle</field-name>
      </cmp-field>


      relation:

      <ejb-relation>
      <ejb-relation-name>utilisateur-profil</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Utilisateur-a-un-Profil</ejb-relationship-role-name>
      Many
      <relationship-role-source>
      <ejb-name>Utilisateur</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>profil</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Profil-a-un-Utilisateur</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>Profil</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      </ejb-relation>


      for jboss.xml, I got:

      <ejb-name>Utilisateur</ejb-name>
      <local-jndi-name>Utilisateur</local-jndi-name>


      <ejb-name>Profil</ejb-name>
      <local-jndi-name>Profil</local-jndi-name>


      for jbosscmp-jdbc.xml

      <ejb-name>Utilisateur</ejb-name>
      <table-name>UTILISATEUR</table-name>
      <cmp-field>
      <field-name>idUser</field-name>
      <column-name>ID_USER</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>codeProfil</field-name>
      <column-name>CODE_PROFIL</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>login</field-name>
      <column-name>LOGIN</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>password</field-name>
      <column-name>PASSWORD</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>derniereCnx</field-name>
      <column-name>DERNIERE_CNX</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>actif</field-name>
      <column-name>ACTIF</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>nom</field-name>
      <column-name>NOM</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>prenom</field-name>
      <column-name>PRENOM</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>description</field-name>
      <column-name>DESCRIPTION</column-name>
      </cmp-field>


      <ejb-name>Profil</ejb-name>
      <table-name>PROFIL</table-name>
      <cmp-field>
      <field-name>codeProfil</field-name>
      <column-name>CODE_PROFIL</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>libelle</field-name>
      <column-name>LIBELLE</column-name>
      </cmp-field>


      <ejb-relation>
      <ejb-relation-name>utilisateur-profil</ejb-relation-name>
      <foreign-key-mapping/>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Utilisateur-a-un-Profil</ejb-relationship-role-name>
      <key-fields/>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Profil-a-plusieurs-Utilisateur</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>codeProfil</field-name>
      <column-name>CODE_PROFIL</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      </ejb-relation>


      And it doesn't work !! :-(
      I need Help !!!

      Thanks for answering ! :-D

      best regards,

      Fred