Because ejbCreate() is only one of many ways your client can request an EJB
(others being ejbFindByPrimaryKey and ejbFindByXXX).  In all these callback
functions you implement, you are returning the PrimaryKey back to the
container so the container can store a reference to the PK in EJBObject.
Hence in subsequent ejbLoad, EJBContext.getPrimaryKey() (which indirectly
calls EJBObject.getPrimaryKey()) is the only consistent way you can retrieve
the PK.

In fact, you CANNOT keep a reference to the PK your self in your bean class
for ejbCreate, ejbFindByPK, or ejbFindByXXX, since the container does NOT
guarantee it will return you the same bean instance in a subsequent ejbLoad.
Hence you can be ejbLoading a completely different bean!

Gene Chuang
Kiko.com


-----Original Message-----
From: Guess [mailto:[EMAIL PROTECTED]]
Sent: Monday, June 25, 2001 9:28 PM
To: [EMAIL PROTECTED]
Subject: necessary to get primary key from entitycontext? (part 2)


I guess I'm not understanding something. Isn't the primary key saved in
the my_primary_key variable below when the ejbCreate is called?
public class myEJB implements EntityBean {
    public String my_primary_key;
    public myEJBPK ejbCreate(String p_primary_key) { my_primary_key =
p_primary_key; }
    // ... more code
}
Then why do we have to use
public void ejbLoad() {
     myEJBPK primaryKey = (myEJBPK) ctx.getPrimaryKey();
     // .. more jdbc code
     statement.setString(1, primaryKey.get_my_primary_key());
}
intead of just doing:
statement.setString(1, my_primary_key); ?
is it necessary to go through the getPrimaryKey() method of the EntityClass
(ctx) ?

----- Original Message -----
From: "Evan Ireland" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, June 25, 2001 11:59 PM
Subject: Re: necessary to get primary key from entitycontext?


> The two places you can best save the key are ejbPostCreate and
ejbActivate.
>
> Guess wrote:
> >
> > hello,
> >
> > i'm writing a BMP ejb. I'm wondering if it's necessary to get
> > the primary key from the EntityContext through the getPrimaryKey()
> > method. Can't I just use the cached primary key in ebjload?
> >
> >
===========================================================================
> > 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".
>
> --
>
____________________________________________________________________________
____
>
> Evan Ireland              Sybase EAServer Engineering
[EMAIL PROTECTED]
>                             Wellington, New Zealand               +64 4
934-5856
>
>
===========================================================================
> 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".
>

===========================================================================
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".

===========================================================================
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