2 Replies Latest reply on Mar 11, 2003 4:59 PM by Jesse Wilson

    Data contains multiple values, but this cmr field is single

    Jeff Markham Newbie

      I've read the other posts in this forum about the subject exception message but please forgive me, I can't seem to either discern the answer (I've purchased the docs and read Chapter 6 over and over) nor overcome the problem.

      I have a 1-to-1 unidirectional relationship (User-->Department) and I get the exception during ejbPostCreate.

      My environment:

      JBoss 3.2.0RC1 w/embedded Tomcat 4.1.18
      Sun JDK 1.4.1-b21
      PostgreSQL 7.3

      ---------------------
      ejb-jar.xml
      ---------------------
      <ejb-relation >
      <ejb-relation-name>departments-pfinet_users</ejb-relation-name>
      <ejb-relationship-role >
      <ejb-relationship-role-name>pfinet_user-has-department</ejb-relationship-role-name>
      One
      <relationship-role-source >
      <ejb-name>PfinetUser</ejb-name>
      </relationship-role-source>
      <cmr-field >
      <cmr-field-name>department</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role >
      <ejb-relationship-role-name>department-has-pfinet_user</ejb-relationship-role-name>
      One
      <relationship-role-source >
      <ejb-name>Department</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      </ejb-relation>
      ---------------------
      jbosscmp-jdbc.xml
      ---------------------
      <ejb-relation>
      <ejb-relation-name>departments-pfinet_users</ejb-relation-name>
      <foreign-key-mapping/>
      <ejb-relationship-role>
      <ejb-relationship-role-name>pfinet_user-has-department</ejb-relationship-role-name>
      <fk-constraint>true</fk-constraint>
      <key-fields/>
      <read-ahead>
      on-load
      </read-ahead>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>department-has-pfinet_user</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>id</field-name>
      <column-name>department</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      </ejb-relation>
      ---------------------
      Entity EJB snippet where 'Department' is the local interface for the Department entity.
      ---------------------
      ...
      public PfinetUserPK ejbCreate(PfinetUserValue data, Department department) throws CreateException
      {
      setUserId(data.getUserId());
      setPfinetUserValue(data);

      return null;
      }
      public void ejbPostCreate(PfinetUserValue data, Department department) throws CreateException
      {
      setDepartment(department);
      }

        • 1. Re: Data contains multiple values, but this cmr field is sin
          Jesse Wilson Newbie

          I wrestled with this problem all day. The solution is to add target-multiple="yes" to the corresponding ejb.relation.

          * @ejb.relation
          * name="Message-ToUser"
          * role-name="Message-has-ToUser"
          * target-ejb="User"
          * target-role-name="ToUser-belongs_to-Message"
          * target-multiple="yes"

          This causes the XDoclet-generated ejb-jar.xml to include Many in the appropriate ejb-relationship-role:

          <ejb-relationship-role>
          <ejb-relationship-role-name>Message-has-ToUser</ejb-relationship-role-name>
          Many
          <relationship-role-source >
          <ejb-name>Message</ejb-name>
          </relationship-role-source>
          <cmr-field >
          <cmr-field-name>to</cmr-field-name>
          </cmr-field>
          </ejb-relationship-role>


          My guess is that JBoss assumes the relationship is 1:1, so it does the search on the wrong table when trying to decide what to insert or remove.

          • 2. Re: Data contains multiple values, but this cmr field is sin
            Jesse Wilson Newbie

            I wrestled with this problem all day. The solution is to add the XDoclet target-multiple="yes" attribute to the ejb.relation tag of the problematic relation:

            * @ejb.relation
            * name="Message-ToUser"
            * role-name="Message-has-ToUser"
            * target-ejb="User"
            * target-role-name="ToUser-belongs_to-Message"
            * target-multiple="yes"

            This corresponds to the following XML in ejb-jar.xml:

            <ejb-relationship-role >
            <ejb-relationship-role-name>Message-has-ToUser</ejb-relationship-role-name>
            Many
            <relationship-role-source >
            <ejb-name>Message</ejb-name>
            </relationship-role-source>
            <cmr-field >
            <cmr-field-name>to</cmr-field-name>
            </cmr-field>
            </ejb-relationship-role>