With auto-generated primary keys the value of the primary key is
obtained from the container, which may generate the key itself or use
some kind of auto-generate facilities of the database, like
auto-increment.

If I want a CMP 2.0 entity bean, say the Customer EJB, to use a
auto-generated primary key of type Integer, then it appears that I would
have to declare the primary key as "undefined" or "deferred" at bean
development time.  Is that correct?

Can I define the primary key type, but not corresponding persistent
fields?  If you define abstract accessor methods for primary key's
field(s), then you must set the primary key field in the ejbCreate()
method (sec. 10.3.5), which I don't want to do with auto-generated
primary keys. I want the container to set auto-generated keys.

Is the following valid?

public abstract class CustomerBean implement EntityBean {

    public Integer ejbCreate( ){}
    public void ejbPostCreate(){}

    public abstract String getLastName(){}
    public abstract void setLastName(){}
    public abstract String getFirstName(){}
    public abstract void setFirstName(){}

    // call back methods
}

public interface CustomerHome extends EJBLocalHome{

    public Customer create() throws CreateException;

    public Cusotmer findByPrimaryKey(Integer primKey)
    throws FinderException;
}

// deployment descriptor
<ejb-jar>
    <enterprise-beans>
        <entity>
            <ejb-name>CustomerEJB</ejb-name>
            <local-home>CustomerHome</home>
            <local>Customer</remote>
            <ejb-class>CustomerBean</ejb-class>
            <persistence-type>Container</persistence-type>
            <prim-key-class>java.lang.Integer</prim-key-class>
            <reentrant>False</reentrant>
            <cmp-version>2.x</cmp-version>
            <cmp-field><field-name>lastName</field-name></cmp-field>
            <cmp-field><field-name>firstName</field-name></cmp-field>
        </entity>

Notice that a primkey-field is not specified and that neither of the
persistent fields match the prim-key-class type.

Richard

--
Richard Monson-Haefel
Author of Enterprise JavaBeans, 2nd Edition  (O'Reilly 2000)
Co-Author of Java Message Service (O'Reilly 2000)
http://www.jMiddleware.com

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to