I think the notion that the primary key of an entity can be changed is
wrong.
By definition the key of an entity defines that entity - if you change the
key you are in effect changing that entity.

You mentioned that you can think of many reasons why you would want to
change the
primary key of an entity - would you care to illustrate a few.

Thanks,
Atul


-----Original Message-----
From: A mailing list for Enterprise JavaBeans development
[mailto:[EMAIL PROTECTED]]On Behalf Of Tim Endres
Sent: Wednesday, April 04, 2001 10:35 AM
To: [EMAIL PROTECTED]
Subject: Re: EJB 1.1 and change of primary key values


And rightly so.

Why should the EJB container restrict me from updating the primary key for
an entity bean's record? I can think of many reasons why the primary key
might be changed, and I can think of many reasons why the primary key should
never be changed. It depends on the context. If you want to be certain that
your primary key can not be updated, then change your setPersonId() method
to throw an exception.

tim.

> Yes, something like
>
>    Person entity has primary key PersonPK
>    Person entity has personId and name attributes.
>    PersonPK has personId attribute.
>    PersonPK ejbCreate( String name ) returns a PersonPK with the newly
> generated value of personId for this bean.
>
> There seems to be nothing keeping me from having a method on the Person
> entity
>
>    setPersonId() which updates the personId attribute within the Person
> entity.  Clearly it cannot update the PersonPK object which the container
> has associated with this entity bean in memory.
>
> In EJB 1.1 there doesn't seem to be anything, not even a mention in the
> spec, that this is undesirable behavior on the part of the bean and also
on
> the part of the bean developer to allow such a thing.
>
> Cheers
>
> -----Original Message-----
> From: José González Gómez [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, April 04, 2001 4:30 AM
> To: [EMAIL PROTECTED]
> Subject: Re: EJB 1.1 and change of primary key values
>
>
>    Jay,
>
>    Correct me if I'm wrong, but I think you are supposing you have some
> fields in your entity bean that act as primary key, is this right?
>
>    regards
>    Jose
>
> Jay Walters wrote:
>
> > To keep ejb-interest from becoming a ghost town I'll ask a question with
I
> > am hoping an obvious answer.
> >
> > In looking at the EJB 1.1 spec I don't see anything that keeps me, a
bean
> > writer from changing the primary key fields within my entity bean (BMP
or
> > CMP); there is at least one container that would propagate these changes
> to
> > a CMP entity bean into the database.
> >
> > My question is, since the primary key associated with the bean doesn't
> > change; and in general we shouldn't be changing the identity of a bean
in
> > midstream, shouldn't the container or the CMP persistence manager
complain
> > about this?  Or at the least shouldn't there be something in the spec
> about
> > not doing this when writing an entity bean?  Otherwise locating the bean
> by
> > primary key will be sort of a hit or miss thing depending on whether
it's
> > been re-loaded since the primary key in the bean is updated.
> >
> > Cheers
> > Jay Walters

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