3 Replies Latest reply on Nov 30, 2003 8:25 AM by jernej

    Can relation cmr-field be part of a composite primary key?

    fred

      Can the cmr-field of a CMP 2.0 unidirectional many-to-one relation be used a primary key? E.g. given:

      <ejb-relation>
      <ejb-relation-name>Publisher-Book</ejb-relation-name>
      <ejb-relationship-role>
      One
      <relationship-role-source>
      <ejb-name>Publisher</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      <ejb-relationship-role>
      Many
      <relationship-role-source>
      <ejb-name>Book</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>publisher</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      </ejb-relation>

      can publisher be use in the Book composite pk? If so, what would the BookPK class and abstract schema pk declaration look like? The goal is to use a publisherId foreign key attribute of the Book table as part of the Book pk. However, there is no cmp-field corresponding to publisherId. Rather, publisherId is the publisher cmr-field column name.

        • 1. Re: Can relation cmr-field be part of a composite primary ke
          dsundstrom

          This should be in the database-persistence forum.

          And the answer is NO. In the future I will allow a cmr-field to be mapped to a cmp-field. This will require read-only relationships and a reordering of create and delete statements. It will be a while.

          -dain

          • 2. Re: Can relation cmr-field be part of a composite primary ke
            fred

            Dain, thanks for the response. I had to chuckle at your remark "This should be in the database-persistence forum", since I was on the verge of suggesting that somebody rename the EJB forum to "EJB design" to emphasize the intent, since at least half of the postings here are not design questions.

            My question was whether there was a design solution using standard EJB 2.0, irrespective of the EJB container. I understand the answer to be:

            There is no standard solution. A solution would require mapping a cmr-field to a cmp-field. That is a vendor extension that JBoss, and probably other vendors, don't yet support.

            That seems to be a big limitation in EJB 2.0, since it is not unusual for a real-world database schema to include a foreign key attribute in an entity table primary key.

            I must be missing something. Surely others face this situation, but I could not find the issue addressed in the spec or any EJB forum, including Sun or ServerSide.

            A work-around is to invent a redundant id field for the primary key, but that is not always possible for a legacy db.

            • 3. Re: Can relation cmr-field be part of a composite primary ke
              jernej

              is this function implemented in JBOss 4 ??