ejbc error 'ejbCreate must return the primary key type'

Discussions

EJB programming & troubleshooting: ejbc error 'ejbCreate must return the primary key type'

  1. Hi

    When I try to deploy Container managed entity bean (example from chapter 9 of Mastering EJB book) in WLS 5.1, I get the following error. I just added hashCode(), equals() methods to the primary class.

    "[9.2.3] In EJB Product, the ejbCreate method: ejbCreate(java.lang.String,java.lang.String,java.lang.String,double) must return the primary key type."

    The signature for the ejbCreate is :

    public void ejbCreate(String productID, String name, String description, double basePrice) throws CreateException, RemoteException

    As per the book , for Container managed, ejbCreate need NOT return of type primary key. I appreciate your help as I could not figure out. May be it is a problem with Deployment descriptor.

    This is the ejb-jar.xml I am using.

    <?xml version="1.0"?>

    <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN' 'http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd'>

    <ejb-jar>
        <enterprise-beans>
          <entity>
    <ejb-name>Product</ejb-name>
    <home>productpkg.ProductHome</home>
    <remote>productpkg.Product</remote>
    <ejb-class>productpkg.ProductBean</ejb-class>
    <persistence-type>Container</persistence-type>
    <prim-key-class>productpkg.ProductPK</prim-key-class>
    <reentrant>False</reentrant>
    <cmp-field>
    <field-name>productID</field-name>
    </cmp-field>
    <cmp-field>
    <field-name>name</field-name>
    </cmp-field>
            <cmp-field>
              <field-name>description</field-name>
            </cmp-field>
            <cmp-field>
              <field-name>basePrice</field-name>
            </cmp-field>
    <primkey-field>productID</primkey-field>
          </entity>
        </enterprise-beans>
        <assembly-descriptor>
          <container-transaction>
    <method>
    <ejb-name>Product</ejb-name>
    <method-intf>Remote</method-intf>
    <method-name>*</method-name>
    </method>
    <trans-attribute>Required</trans-attribute>
          </container-transaction>
        </assembly-descriptor>
    </ejb-jar>
  2. Hi Srinivas,

    You need to have the PK class as the return type.

    From EJB 1.1 for entity beans that use container managed persistence you should return null.




     
  3. Thanks !!

    Srinivas
  4. The home interface should return the PK class type whereas the implementation can return a String.
  5. The method signature MUST return the PK type although in the CMP implementation you just return a null pointer.

    Dave Wolf
    Internet Applications Division
    Sybase