0 Replies Latest reply on Jan 12, 2004 3:51 AM by graste

    CMP field for key not found

    graste Newbie

      Hi,

      although I read some posts on this topic I can't get my foreign-key mapping to work. So I thought it would be okay to ask for help.

      Error on deploy:
      10:02:35,304 WARN [ServiceController] Problem starting service jboss.j2ee:jndiName=ejb/local/Teilnehmer,service=EJB
      org.jboss.deployment.DeploymentException: Role 'KV-hat-Teilnehmer' on Entity Bean 'KvBean' : CMP field for key not found: field name='kVID'
      at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCRelationshipRoleMetaData.loadKeyFields(JDBCRelationshipRoleMetaData.java:432)
      at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCRelationshipRoleMetaData.init(JDBCRelationshipRoleMetaData.java:188)
      at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCRelationMetaData.(JDBCRelationMetaData.java:340)
      ...

      ejb-jar.xml

      <entity>
      <ejb-name>KvBean</ejb-name>
      ...local interfaces etc...
      <abstract-schema-name>KvBean</abstract-schema-name>
      <cmp-field><field-name>kVID</field-name></cmp-field>
      <cmp-field><field-name>nummer</field-name></cmp-field>
      ...other cmp fields, finder...
      </entity>
      
      <entity>
      <ejb-name>TeilnehmerBean</ejb-name>
      ...local interfaces etc...
      <abstract-schema-name>TeilnehmerBean</abstract-schema-name>
      <cmp-field><field-name>teilnehmerID</field-name></cmp-field>
      <cmp-field><field-name>firma</field-name></cmp-field>
      ...other cmp fields, finder...
      </entity>
      
      <relationships>
      
      <ejb-relation>
      <ejb-relation-name>KV-Teilnehmer</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Teilnehmer-gehoert-zu-KV</ejb-relationship-role-name>
      <multiplicity>Many</multiplicity>
      <relationship-role-source>
      <ejb-name>TeilnehmerBean</ejb-name>
      </relationship-role-source>
      <cmr-field><cmr-field-name>kV</cmr-field-name></cmr-field>
      </ejb-relationship-role>
      
      <ejb-relationship-role>
      <ejb-relationship-role-name>KV-hat-Teilnehmer</ejb-relationship-role-name>
      <multiplicity>One</multiplicity>
      <relationship-role-source>
      <ejb-name>KvBean</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>teilnehmer</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>
      </ejb-relation>
      </relationships>
      


      jbosscmp-jdbc.xml:
      <entity>
      <ejb-name>KvBean</ejb-name>
      <table-name>kv</table-name>
      <cmp-field>
      <field-name>kVID</field-name>
      <not-null/>
      <column-name>kvid</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>nummer</field-name>
      <not-null/>
      <column-name>nummer</column-name>
      </cmp-field>
      ...other cmp mappings...
      <!--unknown-pk defined here - Object used for primary-key-class in ejb-jar.xml as well as primkey-field is omitted-->
      <unknown-pk>
      <unknown-pk-class>java.lang.Integer</unknown-pk-class>
      <field-name>pKey</field-name>
      <column-name>pkey</column-name>
      <jdbc-type>INTEGER</jdbc-type>
      <sql-type>SERIAL</sql-type>
      <auto-increment/>
      </unknown-pk>
      <entity-command name="postgresql-fetch-seq"/>
      </entity>
      
      <entity>
      <ejb-name>TeilnehmerBean</ejb-name>
      <table-name>teilnehmer</table-name>
      <cmp-field>
      <field-name>teilnehmerID</field-name>
      <not-null/>
      <column-name>teilnehmer_id</column-name>
      </cmp-field>
      ...other mappings...
      ...unknown-pk defined as above...should probably been moved to default to avoid redefinition on every bean...
      
      <relationships>
      <ejb-relation>
      <ejb-relation-name>KV-Teilnehmer</ejb-relation-name>
      <foreign-key-mapping/>
      
      <ejb-relationship-role>
      <ejb-relationship-role-name>KV-hat-Teilnehmer</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      
      <field-name>kVID</field-name>
       <column-name>fk_kvid</column-name>
      
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      
      <ejb-relationship-role>
      <ejb-relationship-role-name>Teilnehmer-gehoert-zu-KV</ejb-relationship-role-name>
      <key-fields/>
      </ejb-relationship-role>
      
      </ejb-relation>
      </relationships>
      


      So my question probably is easy to answer for you: What do I have to fill in as a field name?

      Btw, I'm using PostGreSQL and the following tables definitions:

      CREATE Table qmsldl.kv (
      pkey serial not null,
      kvid int2 not null,
      ...other attributes...
      CONSTRAINT id_kv UNIQUE (kvid),
      CONSTRAINT pk_kv PRIMARY KEY(pkey)
      );
      
      CREATE Table qmsldl.teilnehmer (
      pkey serial not null,
      teilnehmer_id integer not null,
      fk_kvid int2,
      firma varchar(255),
      ...other attributes...
      CONSTRAINT id_teilnehmer UNIQUE (teilnehmer_id),
      CONSTRAINT pk_teilnehmer PRIMARY KEY(pkey),
      CONSTRAINT fk_teilnehmer_kvid FOREIGN KEY (fk_kvid) REFERENCES qmsldl.kv(kvid)
      );
      



      TeilnehmerBean code:
       public abstract Kv getKV();
       public abstract void setKV(Kv kvid);
      
       /* primary key; see ejb-jar.xml and jbosscmp-jdbc.xml */
       public abstract Object getPKey();
       public abstract void setPKey(Object pkey);
      
       public abstract Integer getTeilnehmerID();
       public abstract void setTeilnehmerID(Integer id);
      ...
      


      KvBean code:
       public abstract Collection getTeilnehmer();
       public abstract void setTeilnehmer(Collection collection);
      
       /* primary key; see ejb-jar.xml and jbosscmp-jdbc.xml */
       public abstract Object getPKey();
       public abstract void setPKey(Object pkey);
      
       public abstract Integer getKVID();
       public abstract void setKVID(Integer id);
      ...
      


      Any suggestions for a newbie? :|

      Thanks in advance.

      Steffen Gransow