2 Replies Latest reply on Jun 23, 2006 4:44 PM by Don Jonsn

    M:N CMP Relationship with unknown Primay Key fails with comp

    Don Jonsn Newbie

      I want to create an m:n relationship between a User and Appointment.

      XDoclet in User looks like this:
      /** @ejb.bean name="User"
      * description="An user with a container generated pk"
      * display-name="User"
      * jndi-name="ejb/User"
      * local-jndi-name = "ejb/UserLocalHome"
      * type="CMP"
      * transaction-type="Container"
      * cmp-version="2.x"
      * view-type="local"
      * @jboss.unknown-pk
      * class="java.lang.Integer"
      * column-name="pk"
      * field-name="id"
      * sql-type="INTEGER"
      * jdbc-type="INTEGER"
      * auto-increment="true"
      * @jboss.entity-command
      * name="hsqldb-fetch-key"
      * class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCHsqldbCreateCommand"
      * @ejb.pk
      * class="java.lang.Integer"
      * generate="false"

      and the get-ter for the field:
      /**
      * @return Collection of appointments.
      * @ejb.interface-method view-type="local"
      * @ejb.relation
      * name="UserAppointment"
      * role-name = "user-has-appointments"
      * target-ejb = "Appointment"
      * target-role-name = "appointment-has-users"
      * target-multiple = "yes"
      * @jboss.relation
      * related-pk-field = "id"
      * fk-column = "fk"
      */
      public abstract java.util.Collection getAppointments();

      XDoclet in Apointment looks like this (basically the same as in User):
      /** @ejb.bean name="Appointment"
      * description="An appointment with a container generated pk"
      * display-name="Appointment"
      * jndi-name="ejb/Appointment"
      * type="CMP"
      * transaction-type="Container"
      * cmp-version="2.x"
      * view-type="local"
      * @jboss.unknown-pk
      * class="java.lang.Integer"
      * column-name="pk"
      * field-name="id"
      * sql-type="INTEGER"
      * jdbc-type="INTEGER"
      * auto-increment="true"
      * @jboss.entity-command
      * name="hsqldb-fetch-key"
      * class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCHsqldbCreateCommand"
      * @ejb.pk
      * class="java.lang.Integer"
      * generate="false"

      and the get-ter for the field (also basically the same as in User):
      /**
      * @return Collection of users.
      * @ejb.interface-method view-type="local"
      * @ejb.relation
      * name = "UserAppointment"
      * role-name = "appointment-has-users"
      * target-ejb = "User"
      * target-role-name = "user-has-appointments"
      * target-multiple = "yes"
      * @jboss.relation
      * related-pk-field = "id"
      * fk-column = "fk"
      */
      public abstract java.util.Collection getUsers();

      The relationship in the created jbosscmp-jdbc.xml looks ok to me:

      <ejb-relation>
      <ejb-relation-name>UserAppointment</ejb-relation-name>
      <relation-table-mapping>
      </relation-table-mapping>
      <ejb-relationship-role>
      <ejb-relationship-role-name>user-has-appointments</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>id</field-name>
      <column-name>pk</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>appointment-has-users</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>id</field-name>
      <column-name>pk</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      </ejb-relation>


      But still when I try to deplay with JBoss 4.0.4 I get following error:
      org.jboss.deployment.DeploymentException: Both roles of a relation-table mapped relationship must have key fields: ejb-relation-name=UserAppointment

      Has anyone a hint?

      Cheers, Jons.