0 Replies Latest reply on Jun 15, 2006 4:30 PM by A N

    How to use a primary Key CMP field in CMR?

    A N Newbie

      Hi,

      I'm trying to use a Primary Key CMP field in a CMR relationship.

      This CMP field is part of a composite primary key within the entity bean where I define the CMR relationship. The declaration within the EJB is as follows:

       /**
       * @ejb:persistent-field
       * @ejb:pk-field
       * @ejb:interface-method
       *
       * @jboss.column-name name="native_service_unit"
       */
       abstract public String getNativeServiceUnitId();
      
       /**
       * @ejb:interface-method
       * @ejb:relation
       * name="NativeServiceUnit-NativeCategory"
       * role-name="many-nativecategory-has-one-nativeserviceunit"
       *
       * @jboss.relation
       * fk-column="NATIVE_SERVICE_UNIT"
       * related-pk-field="nativeServiceUnitId"
       */
       abstract public NativeServiceUnitLocal getNativeServiceUnit();
      


      The corresponding generated XML segments are:

      jbosscmp-jdbc.xml:
      < entity >

      <entity>
       <ejb-name>NativeCategory</ejb-name>
      
       <table-name>NATIVE_CATEGORY</table-name>
      
       <cmp-field>
       <field-name>nativeCategoryId</field-name>
       <column-name>native_category_id</column-name>
      
       </cmp-field>
       <cmp-field>
       <field-name>nativeServiceUnitId</field-name>
       <column-name>native_service_unit</column-name>
      
       </cmp-field>
      </entity>
      


      jbosscmp-jdbc.xml:
      <ejb-relation>

      <ejb-relation>
       <ejb-relation-name>NativeServiceUnit-NativeCategory</ejb-relation-name>
      
       <ejb-relationship-role>
       <ejb-relationship-role-name>many-nativecategory-has-one-nativeserviceunit</ejb-relationship-role-name>
       <key-fields/>
      
       </ejb-relationship-role>
       <ejb-relationship-role>
       <ejb-relationship-role-name>one-nativeserviceunit-has-many-nativecategory</ejb-relationship-role-name>
       <key-fields>
       <key-field>
       <field-name>nativeServiceUnitId</field-name>
       <column-name>NATIVE_SERVICE_UNIT</column-name>
       </key-field>
       </key-fields>
      
       </ejb-relationship-role>
      </ejb-relation>
      


      The problem is that when I try to create an entity, I get the following error:
      2006-06-15 15:41:17,312 ERROR [org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.NativeCategory] Could not create entity
      java.sql.SQLException: Column 'native_service_unit' specified twice
      


      Is there any workaround to this situation? I know that this works well on other servers.

      Thanks!