1 Reply Latest reply on Feb 4, 2005 11:09 AM by agoncal

    Method is not a known CMP field accessor, CMR field accessor

    agoncal

      Hi, I've got a bunch of CMPs (running on JBoss 3.2.5) representing an order with orderLine. Here are the links:

      Order -1----*-> OrderLine -1----1-> Item
      |
      V
      Customer

      My problem comes when I want to create an order. With existing Customer and Items, I want to create (in one go) an Order with its OrderLines. When I do that I've got the following exception

      15:53:01,187 ERROR [LogInterceptor] TransactionRolledbackException in method: public abstract java.lang.String com.yaps.
      petstore.server.service.order.OrderService.createOrder(java.lang.String,java.util.Map) throws javax.ejb.CreateException,
      com.yaps.petstore.common.exception.CheckException,java.rmi.RemoteException, causedBy:
      javax.ejb.EJBException: Method is not a known CMP field accessor, CMR field accessor, or ejbSelect method: methodName=setOrder
       at org.jboss.ejb.plugins.cmp.bridge.EntityBridgeInvocationHandler.invoke(EntityBridgeInvocationHandler.java:83)
       at org.jboss.proxy.compiler.Runtime.invoke(Runtime.java:62)
       at com.yaps.petstore.server.domain.orderline.OrderLineBean$Proxy.setOrder(<generated>)
       at com.yaps.petstore.server.domain.orderline.OrderLineBean.ejbPostCreate(Unknown Source)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at org.jboss.ejb.plugins.CMPPersistenceManager.postCreateEntity(CMPPersistenceManager.java:235)
       at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.postCreateEntity(CachedConnectionInterceptor
      .java:277)



      I've localised the problem but I can't solve it or explain it. It's in the postCreate of the OrderLine CMP when it calls the setOrder method. If I take it our, the exception doesn't occur but in the database I've got a foreign key set to null, normal.

      public String ejbCreate(int quantity, double unitCost, OrderLocal order, ItemLocal item) throws CreateException, CheckException {
      
       setId(getUniqueId(COUNTER_NAME));
       setUnitCost(unitCost);
       setQuantity(quantity);
       return null;
       }
      
       public void ejbPostCreate(int quantity, double unitCost, OrderLocal order, ItemLocal item) throws CreateException, CheckException {
      
       setOrder(order);
       setItem(item);
       }



      The method setOrder IS a CMR Method and it's declared abstract like all the other getters and setters

      public abstract int getQuantity();
       public abstract void setQuantity(final int quantity);
      
       public abstract double getUnitCost();
       public abstract void setUnitCost(final double unitCost);
      
       public abstract OrderLocal getOrder();
       public abstract void setOrder(final OrderLocal order);
      
       public abstract ItemLocal getItem();
       public abstract void setItem(final ItemLocal item);


      And here are bits of the ejb-jar.xml

      <entity>
       <display-name>OrderEB</display-name>
       <ejb-name>OrderBean</ejb-name>
       <local-home>com.yaps.petstore.server.domain.order.OrderLocalHome</local-home>
       <local>com.yaps.petstore.server.domain.order.OrderLocal</local>
       <ejb-class>com.yaps.petstore.server.domain.order.OrderBean</ejb-class>
       <persistence-type>Container</persistence-type>
       <prim-key-class>java.lang.String</prim-key-class>
       <reentrant>False</reentrant>
       <cmp-version>2.x</cmp-version>
       <abstract-schema-name>Order</abstract-schema-name>
       <cmp-field>
       <field-name>id</field-name>
       </cmp-field>
       <cmp-field>
       <field-name>status</field-name>
       </cmp-field>
       <cmp-field>
       <field-name>orderDate</field-name>
       </cmp-field>
       <cmp-field>
       <field-name>firstname</field-name>
       </cmp-field>
       <cmp-field>
       <field-name>lastname</field-name>
       </cmp-field>
       <primkey-field>id</primkey-field>
       </entity>
      
       <entity>
       <display-name>OrderLineEB</display-name>
       <ejb-name>OrderLineBean</ejb-name>
       <local-home>com.yaps.petstore.server.domain.orderline.OrderLineLocalHome</local-home>
       <local>com.yaps.petstore.server.domain.orderline.OrderLineLocal</local>
       <ejb-class>com.yaps.petstore.server.domain.orderline.OrderLineBean</ejb-class>
       <persistence-type>Container</persistence-type>
       <prim-key-class>java.lang.String</prim-key-class>
       <reentrant>False</reentrant>
       <cmp-version>2.x</cmp-version>
       <abstract-schema-name>OrderLine</abstract-schema-name>
       <cmp-field>
       <field-name>id</field-name>
       </cmp-field>
       <cmp-field>
       <field-name>quantity</field-name>
       </cmp-field>
       <cmp-field>
       <field-name>unitCost</field-name>
       </cmp-field>
       <primkey-field>id</primkey-field>
       </entity>


      And the relationship part

      <ejb-relation>
       <ejb-relation-name>OrderBean - OrderLineBean</ejb-relation-name>
       <ejb-relationship-role>
       <ejb-relationship-role-name>order-has-orderLines</ejb-relationship-role-name>
       <multiplicity>One</multiplicity>
       <relationship-role-source>
       <ejb-name>OrderBean</ejb-name>
       </relationship-role-source>
       <cmr-field>
       <cmr-field-name>orderLines</cmr-field-name>
       <cmr-field-type>java.util.Collection</cmr-field-type>
       </cmr-field>
       </ejb-relationship-role>
      
       <ejb-relationship-role>
       <ejb-relationship-role-name>orderLine-belongs_to-order</ejb-relationship-role-name>
       <multiplicity>Many</multiplicity>
       <relationship-role-source>
       <ejb-name>OrderLineBean</ejb-name>
       </relationship-role-source>
       </ejb-relationship-role>
       </ejb-relation>


      Does anybody have an idea, I've been looking everywhere and can't find any solution.

      Thanks in advance

      Antonio

        • 1. Re: Method is not a known CMP field accessor, CMR field acce
          agoncal

          I've finally found the problem, I didn't take in account that the Order -> OrderLine relationship was bidirectional. Here is the ejb-jar.xml that works, I've just added the

          <cmr-field>
           <cmr-field-name>order</cmr-field-name>
          </cmr-field>


          It looks like that

          <ejb-relation>
           <ejb-relation-name>OrderBean - OrderLineBean</ejb-relation-name>
           <ejb-relationship-role>
           <ejb-relationship-role-name>order-has-orderLines</ejb-relationship-role-name>
           <multiplicity>One</multiplicity>
           <relationship-role-source>
           <ejb-name>OrderBean</ejb-name>
           </relationship-role-source>
           <cmr-field>
           <cmr-field-name>orderLines</cmr-field-name>
           <cmr-field-type>java.util.Collection</cmr-field-type>
           </cmr-field>
           </ejb-relationship-role>
          
           <ejb-relationship-role>
           <ejb-relationship-role-name>orderLine-belongs_to-order</ejb-relationship-role-name>
           <multiplicity>Many</multiplicity>
           <relationship-role-source>
           <ejb-name>OrderLineBean</ejb-name>
           </relationship-role-source>
           <cmr-field>
           <cmr-field-name>order</cmr-field-name>
           </cmr-field>
           </ejb-relationship-role>
           </ejb-relation>