1 Reply Latest reply on Jun 17, 2003 12:16 PM by Pablo Delgado

    CMR field as a part of the primary key

    Pablo Delgado Newbie


      I see in the post http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/ similiar question but this post was in January 2003 so I hope there is a solution!

      I have a One-to-Many relationship between two entity beans and I need the primary key (an integer field) of the one-side entity bean of the relationship to be also part of the primary key of the many-side entity bean of the relationship.
      I see that others CMP engines (like Resin) manage it correctly and I read that in 3.2 version of Jboss this problem will be fixed but ... does anyone something new? a way that I can continue with my project? is setting the CMR field as a CMP field and managing the relationship with BMP the only solution?

      Any help would be appreciated.


        • 1. Re: CMR field as a part of the primary key
          Pablo Delgado Newbie

          Hello again,

          Some days after posting the previous message I found the solution (I upgraded from Jboss 3.0.7 to 3.2.0 but I'm not sure if it was part of the reason)

          If you want to have a CMR field as part of the primary key of an EB, you have to create the same field also as a CMP field and join them at the column-name attribute, I mean, if you have this relationship

          Token (1) --------------- (*) Availability

          in the availability EB .... (using xdoclet)

          * @ejb.pk-field
          * @ejb.interface-method
          * @ejb.persistent-field
          * @ejb.persistence
          * column-name="id_token_fk"
          * jdbc-type="BIGINT"
          * sql-type="bigint"
          abstract public Long getIdtoken ();

          and also the CMR field ...
          * CMR abstract accesors TOKEN-AVAILABILITY
          * @ejb.interface-method
          * view-type="local"
          * @ejb.relation
          * name="token-availability"
          * role-name="availability-belongs-to-token"
          * target-multiple="yes"
          * @jboss.relation
          * related-pk-field="idtoken"
          * fk-column="id_token_fk"
          * fk-constraint="true"

          public abstract TokenLocal getToken();

          where if you notice, the "column-name" and "fk-column" have the same value (id_token_fk).

          Doing this, you keep the relationship and the all the constraints you may need and it does not create two columns. It only creates one and is part of the relationship and part of the PK of the EB.

          I hope this information may help somebody.


          Pablo Delgado