1 Reply Latest reply on Apr 30, 2003 6:49 PM by ihateloginnames

    cmr "target side" entity populated with wrong primary key va

    ihateloginnames

      I have a simple prototype app that has two cmp entities (RequisitionBean, LineItemBean) with cmr that relates an aggregate of LineItem entities on a Requisition entity.

      The ids (primary keys) for each of the entities are derived from a sequence number generator. I can create a requisition and add multilple line items to it. Further, I can verify that the entities are created correctly in the database. For example, the database shows me a requisition with "req_id"=10 and two line items with "line_id"=1 and "line_id"=2 (both line items have a foreign key that references "req_id"=10).

      My problem is that when I programatically inspect the line item entities' lineId fields (which is the primary key for the line item entity) the value returned is the value of the primary key of the requisition. That is, for the example above I see 10 as the lineId for both line item entities (I expected to see 1 and 2). It seems as if JBoss is populating the target side entities' primary key values with the value of the source entity's primary key field.

      Below are a couple of snippets from my Bean code (including xdoclet tags). Can anyone point out what I have done wrong, or is this a jboss bug?

      Thanks,

      Troy

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

      public abstract class RequisitionBean implements javax.ejb.EntityBean {

      ...

      /**
      * Returns the reqId
      *
      * @return the reqId
      *
      * @ejb.pk-field
      * @ejb.interface-method view-type="local"
      * @ejb.persistence column-name="req_id"
      */
      public abstract int getReqId();

      ...

      /**
      * This is a uni-directional one-to-many relationship CMR method
      *
      * @return a java.util.Collection of related
      * com.partnet.rqs.ejbi.LineItemLocal.
      *
      * @ejb.interface-method view-type="local"
      *
      * @ejb.relation
      * name="requisition-line_items"
      * role-name="requisition-has-line_items"
      * target-cascade-delete="yes"
      * target-ejb="LineItem"
      * target-role-name="line_items-belong-to-a-requisition"
      * target-multiple="no"
      *
      * @jboss.target-relation
      * fk-constraint="true"
      * fk-column="req_id"
      * related-pk-field="reqId"
      */
      public abstract java.util.Collection getLineItems();

      ...
      }



      public abstract class LineItemBean implements javax.ejb.EntityBean {

      ...

      /**
      * Returns the lineId
      *
      * @return the lineId
      *
      * @ejb.pk-field
      * @ejb.interface-method view-type="local"
      * @ejb.persistence column-name="line_id"
      */
      public abstract int getLineId();

      ...

      /**
      * Returns the reqId
      *
      * @return the reqId
      *
      * @ejb.interface-method view-type="local"
      * @ejb.persistence column-name="req_id"
      */
      public abstract int getReqId();

      ...
      }