1 Reply Latest reply on Jul 17, 2003 3:19 AM by Juha Lindfors

    1:1 Relationships and cmp fields with Xdoclet

    dn666 Newbie

      I simply dont get it !!!!
      How do i create a 1:1 relationship with xdoclet.



      whats wrong jboss keeps complaining:
      CMP field for key not found: field name=status_idsLocal
      the beans are so simple they can get

      Im using jboss-3.2.1

      The database tables are:

      Codec_master
      codec_key (pk)
      status_id (fk - Status_ids -> status_id)

      Status_ids
      status_id (pk)
      descrip




      Here are my two beans, with the xdoclet tags:


      The Codec_masterBean:

      package dk.stream.ejbrelationtest;
      import javax.ejb.EntityBean;
      import javax.ejb.EntityContext;
      import javax.ejb.CreateException;
      import java.sql.Timestamp;
      import java.util.Collection;
      /**
      * @ejb.bean
      * name="Codec_master"
      * type="CMP"
      * view-type="local"
      * local-jndi-name="local/Codec_master"
      * primkey-field="codec_key"
      * schema="Codec_master"
      * cmp-version="2.x"
      * view-type="local"
      * @ejb.value-object
      * name="Codec_master"
      * match="*"
      * @ejb.transaction
      * type="Required"
      * @ejb.util
      * generate="physical"
      * @ejb.persistence
      * table-name="codec_master"
      * @ejb:pk class="java.lang.Long"
      *
      * @ejb:home generate="local"
      * @ejb:finder
      * signature= "java.util.Collection findAll()"
      * query ="SELECT OBJECT(o) FROM Codec_master AS o"
      *
      *
      * @jboss:create-table false
      * @jboss:remove-table false
      */
      public abstract class Codec_masterBean implements EntityBean {
      private EntityContext context;
      /**
      * @ejb.create-method
      */
      public Long ejbCreate(Long codecKey, Status_idsLocal status_idsLocal) throws CreateException {
      setCodec_key(codecKey);
      setStatus_idsLocal(status_idsLocal);
      return codecKey;
      }

      public void ejbPostCreate(Long codecKey, Status_idsLocal statusID) {
      }

      public void ejbActivate() {
      }

      public void ejbLoad() {
      }

      public void ejbPassivate() {
      }

      public void ejbRemove() {
      }

      public void ejbStore() {
      }

      public void setEntityContext(EntityContext ctx) {
      this.context = ctx;
      }

      public void unsetEntityContext() {
      this.context = null;
      }
      /** @ejb:pk-field
      * @ejb:interface-method view-type="local"
      * @ejb:persistent-field
      */
      public abstract Long getCodec_key();
      /** @ejb:interface-method view-type="local"
      * @ejb:persistent-field
      */
      public abstract void setCodec_key(Long newCodec_key);

      /**
      * @return a Status_ids object
      * @ejb.interface-method
      * @ejb:persistent-field
      * @ejb.relation
      * name="Codec_master-Status_id"
      * role-name="Codec_master-has-a-Status_id"
      * target-ejb="Status_ids"
      * target-role-name="Status_ids-belongs-to-Codec_master"
      * target-multiple="No"
      *
      * @jboss.relation
      * related-pk-field="status_id"
      * fk-column="status_idsLocal"
      * fk-constraint="true"
      *
      * @jboss.target-relation
      * related-pk-field="status_idsLocal"
      * fk-column="status_id"
      * fk-constraint="true"
      */
      public abstract Status_idsLocal getStatus_idsLocal();
      /** @ejb:interface-method view-type="local"
      */
      public abstract void setStatus_idsLocal(Status_idsLocal status_idsLocal);
      }





      ---------------------------------------


      The Status_idsBean:

      package dk.stream.ejbrelationtest;

      import javax.ejb.EntityBean;
      import javax.ejb.EntityContext;
      import javax.ejb.CreateException;


      /**
      * @ejb.bean
      * name="Status_ids"
      * type="CMP"
      * view-type="local"
      * local-jndi-name="local/Status_ids"
      * primkey-field="status_id"
      * schema="Status_ids"
      * cmp-version="2.x"
      * view-type="local"
      * @ejb.value-object
      * name="Status_ids"
      * match="*"
      * @ejb.transaction
      * type="Required"
      * @ejb.util
      * generate="physical"
      * @ejb:pk class="java.lang.String"
      *
      * @ejb:home generate="local"
      * @ejb:finder
      * signature= "java.util.Collection findAll()"
      * query ="SELECT OBJECT(o) FROM Status_ids AS o"
      *
      * @jboss:create-table false
      * @jboss:remove-table false
      */

      public abstract class Status_idsBean implements EntityBean {
      private EntityContext context;
      /**
      * @ejb.create-method
      */
      public String ejbCreate(String status_id, String descrip) throws CreateException {
      setStatus_id(status_id);
      setDescrip(descrip);
      return status_id;
      }

      public void ejbPostCreate(String status_id, String descrip) {
      }

      public void ejbActivate() {
      }

      public void ejbLoad() {
      }

      public void ejbPassivate() {
      }

      public void ejbRemove() {
      }

      public void ejbStore() {
      }

      public void setEntityContext(EntityContext ctx) {
      this.context = ctx;
      }

      public void unsetEntityContext() {
      this.context = null;
      }

      /** @ejb:pk-field
      * @ejb:interface-method view-type="local"
      * @ejb:persistent-field
      */
      public abstract String getStatus_id();
      /** @ejb:interface-method view-type="local"
      */
      public abstract void setStatus_id(String newStatus_id);


      /** @ejb:interface-method view-type="local"
      * @ejb:persistent-field
      */
      public abstract String getDescrip();
      /** @ejb:interface-method view-type="local"
      */
      public abstract void setDescrip(String newDescrip);
      }




      And the generated deployment descriptors:


      ejb-jar.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">

      <ejb-jar >

      No Description.
      <display-name>Generated by XDoclet</display-name>

      <enterprise-beans>

      <!-- Session Beans -->

      <!--
      To add session beans that you have deployment descriptor info for, add
      a file to your merge directory called session-beans.xml that contains
      the markup for those beans.
      -->

      <!-- Entity Beans -->

      <![CDATA[No Description.]]>

      <ejb-name>Status_ids</ejb-name>

      <local-home>dk.stream.ejbrelationtest.Status_idsLocalHome</local-home>
      dk.stream.ejbrelationtest.Status_idsLocal

      <ejb-class>dk.stream.ejbrelationtest.Status_idsBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.String</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>Status_ids</abstract-schema-name>
      <cmp-field >
      <![CDATA[]]>
      <field-name>status_id</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[]]>
      <field-name>descrip</field-name>
      </cmp-field>
      <primkey-field>status_id</primkey-field>


      <query-method>
      <method-name>findAll</method-name>
      <method-params>
      </method-params>
      </query-method>
      <ejb-ql><![CDATA[SELECT OBJECT(o) FROM Status_ids AS o]]></ejb-ql>




      <![CDATA[No Description.]]>

      <ejb-name>Codec_master</ejb-name>

      <local-home>dk.stream.ejbrelationtest.Codec_masterLocalHome</local-home>
      dk.stream.ejbrelationtest.Codec_masterLocal

      <ejb-class>dk.stream.ejbrelationtest.Codec_masterBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Long</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>Codec_master</abstract-schema-name>
      <cmp-field >
      <![CDATA[]]>
      <field-name>codec_key</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[]]>
      <field-name>status_idsLocal</field-name>
      </cmp-field>
      <primkey-field>codec_key</primkey-field>


      <query-method>
      <method-name>findAll</method-name>
      <method-params>
      </method-params>
      </query-method>
      <ejb-ql><![CDATA[SELECT OBJECT(o) FROM Codec_master AS o]]></ejb-ql>



      <!--
      To add entity beans that you have deployment descriptor info for, add
      a file to your merge directory called entity-beans.xml that contains
      the markup for those beans.
      -->

      <!-- Message Driven Beans -->
      <!--
      To add message driven beans that you have deployment descriptor info for, add
      a file to your merge directory called message-driven-beans.xml that contains
      the <message-driven></message-driven> markup for those beans.
      -->

      </enterprise-beans>

      <!-- Relationships -->

      <ejb-relation >
      <ejb-relation-name>Codec_master-Status_id</ejb-relation-name>
      <!-- unidirectional -->
      <ejb-relationship-role >
      <ejb-relationship-role-name>Codec_master-has-a-Status_id</ejb-relationship-role-name>
      One
      <relationship-role-source >
      <ejb-name>Codec_master</ejb-name>
      </relationship-role-source>
      <cmr-field >
      <cmr-field-name>status_idsLocal</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role >
      <ejb-relationship-role-name>Status_ids-belongs-to-Codec_master</ejb-relationship-role-name>
      One
      <relationship-role-source >
      <ejb-name>Status_ids</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      </ejb-relation>


      <!-- Assembly Descriptor -->
      <assembly-descriptor >

      <!-- finder permissions -->

      <!-- finder permissions -->

      <!-- transactions -->
      <container-transaction >

      <ejb-name>Status_ids</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction >

      <ejb-name>Codec_master</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>

      <!-- finder transactions -->
      </assembly-descriptor>

      </ejb-jar>



      ---------------------------------

      And jbosscmp-jdbc.xml:



      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 3.0//EN" "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_0.dtd">

      <jbosscmp-jdbc>

      java:/SapdbDS
      <datasource-mapping>SapDB</datasource-mapping>


      <enterprise-beans>


      <ejb-name>Status_ids</ejb-name>
      <create-table>false</create-table>
      <remove-table>false</remove-table>

      <cmp-field>
      <field-name>descrip</field-name>
      <column-name>descrip</column-name>

      </cmp-field>
      <cmp-field>
      <field-name>status_id</field-name>
      <column-name>status_id</column-name>

      </cmp-field>
      <!--
      To define load groups for this entity, write a file named
      jbosscmp-jdbc-load-Status_idsBean.xml and put it in
      your mergedir. Write it according to the following DTD slice:
      <!ELEMENT load-groups (load-group+)>
      <!ELEMENT load-group (load-group-name, description?, field-name+)>
      <!ELEMENT load-group-name (#PCDATA)>
      <!ELEMENT description (#PCDATA)>
      <!ELEMENT field-name (#PCDATA)>
      <!ELEMENT eager-load-group (#PCDATA)>
      <!ELEMENT lazy-load-groups (load-group-name+)>
      -->




      <ejb-name>Codec_master</ejb-name>
      <create-table>false</create-table>
      <remove-table>false</remove-table>

      <cmp-field>
      <field-name>codec_key</field-name>
      <column-name>codec_key</column-name>

      </cmp-field>
      <cmp-field>
      <field-name>status_idsLocal</field-name>
      <column-name>status_idsLocal</column-name>

      </cmp-field>
      <cmp-field>
      <field-name>codec_key</field-name>
      <column-name>codec_key</column-name>

      </cmp-field>
      <!--
      To define load groups for this entity, write a file named
      jbosscmp-jdbc-load-Codec_masterBean.xml and put it in
      your mergedir. Write it according to the following DTD slice:
      <!ELEMENT load-groups (load-group+)>
      <!ELEMENT load-group (load-group-name, description?, field-name+)>
      <!ELEMENT load-group-name (#PCDATA)>
      <!ELEMENT description (#PCDATA)>
      <!ELEMENT field-name (#PCDATA)>
      <!ELEMENT eager-load-group (#PCDATA)>
      <!ELEMENT lazy-load-groups (load-group-name+)>
      -->



      </enterprise-beans>


      <ejb-relation>
      <ejb-relation-name>Codec_master-Status_id</ejb-relation-name>
      <foreign-key-mapping/>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Codec_master-has-a-Status_id</ejb-relationship-role-name>
      <fk-constraint>true</fk-constraint>
      <key-fields>
      <key-field>
      <field-name>status_idsLocal</field-name>
      <column-name>status_id</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Status_ids-belongs-to-Codec_master</ejb-relationship-role-name>
      <fk-constraint>true</fk-constraint>
      <key-fields>
      <key-field>
      <field-name>status_id</field-name>
      <column-name>status_idsLocal</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      </ejb-relation>


      </jbosscmp-jdbc>

        • 1. Re: 1:1 Relationships and cmp fields with Xdoclet
          Juha Lindfors Master

          Is it because this

          * @jboss.target-relation
          * related-pk-field="status_idsLocal"
          * fk-column="status_id"
          * fk-constraint="true"

          in the target relation your pk field is status_id not status_idsLocal...?

          I admit I did not go and look at xdoclet docs to find out what these relation tags are supposed to do, I find debugging xdoclet rather frustrating.