3 Replies Latest reply on Aug 7, 2002 1:17 PM by Greg Greaves

    CMR problem

    Greg Greaves Newbie

      Consider the following scenario:

      Table t_parent
      ==============
      id int primary key
      name varchar(50)

      Table t_child
      =============
      parent_id primary key,
      id primary key,
      name

      Entity beans are created on both tables and there is a 1 to many bidirectional CMR relationship between t_parent and t_child

      Inserting a t_child yields the following exception:

      2002-08-01 15:46:21,071 ERROR [org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.TChild] Could not create entity
      java.sql.SQLException: Try to insert null into a non-nullable column in statement [INSERT INTO T_CHILD (parent_id, id, name, parent_id) VALUES (1, 1, NULL, NULL)]

      Notice that parent_id is specified twice in the insert statement, once for the composite primary key of the t_child entity and (I assume) once for the relationship between t_child and t_parent.

      Any idea what is going on here?

      Thanks,
      -Greg

        • 1. Re: CMR problem
          Greg Greaves Newbie

          Additional info:

          jbosscmp-jdbc.xml relationships section

          ==================================

          <ejb-relation>
          <ejb-relation-name>tParent-tChild</ejb-relation-name>
          <foreign-key-mapping></foreign-key-mapping>
          <ejb-relationship-role>
          <ejb-relationship-role-name>TParentRelationshipRole</ejb-relationship-role-name>
          <key-fields>
          <key-field>
          <field-name>id</field-name>
          <column-name>parent_id</column-name>
          </key-field>
          </key-fields>
          </ejb-relationship-role>
          <ejb-relationship-role>
          <ejb-relationship-role-name>TChildRelationshipRole</ejb-relationship-role-name>
          </ejb-relationship-role>
          </ejb-relation>

          ==========================================

          ejb-jar.xml relationships section
          =========================================

          <ejb-relation>
          <ejb-relation-name>tParent-tChild</ejb-relation-name>
          <ejb-relationship-role>
          tParent
          <ejb-relationship-role-name>TParentRelationshipRole</ejb-relationship-role-name>
          One
          <relationship-role-source>
          tParent
          <ejb-name>TParent</ejb-name>
          </relationship-role-source>
          <cmr-field>
          tChild
          <cmr-field-name>tChild</cmr-field-name>
          <cmr-field-type>java.util.Collection</cmr-field-type>
          </cmr-field>
          </ejb-relationship-role>
          <ejb-relationship-role>
          tChild
          <ejb-relationship-role-name>TChildRelationshipRole</ejb-relationship-role-name>
          Many
          <relationship-role-source>
          tChild
          <ejb-name>TChild</ejb-name>
          </relationship-role-source>
          <cmr-field>
          tParent
          <cmr-field-name>tParent</cmr-field-name>
          </cmr-field>
          </ejb-relationship-role>
          </ejb-relation>

          ==========================================

          -Greg

          • 2. Re: CMR problem
            Dain Sundstrom Master

            A foreign key can not be part of the primay key.

            • 3. Re: CMR problem
              Greg Greaves Newbie

              Welcome back Dain! I suppose gurus need a few days off every now and then.

              The EJB runs fine on Borland Enterprise Server and Sybase EAServer. Is there some place you can point me in the spec where it says that a foreign key can't be part of the primary key?

              Thanks,
              -Greg