Hi!
Murali Krishna Devarakonda wrote:
> There's no way to change the primary key of an object in EJB. It's just
> the way it is.
>
> Rickard,
> That's a good point.
>
> Now the questions in my mind are:
> 1. This cannot apply to BMP. Who's stopping me from changing the
> "password" field, and writing out the modified field(along with all the
> other fields) in ejbStore?
Noone will stop you but your system will deteriorate as the server still
thinks that it has the old pk, since that is what you gave it from the
create constructor. Don't do it.
> 2. Even in CMP, is it explicitly forbidden in the spec? I don't remember
> it that way...
No, it is not explicitly forbidden as it is assumed that the meaning of
"primary key" is that it is the identity of the object, and will as such
never change.
> Implicitly, you may expect that behavior, but isn't it totally
> dependent on the container implementation. I mean, Vendor A might say, the
> User exists, hence the primary key fields should never be written to the
> database. But Vendor B might just write out all the containerManagedFields,
> including "login" and "password" to the database. I could even change the
> "login" in that case!
> Isn't it possible? Now, even if the containers implement it in a
> standard way- i.e., enforce the principle that the primary key fields cannot
> be modified, how do they do it?
Because they are more than likely to maintain a cache of the beans and
this will hold pk's. If you create a User "rickard" and then change it
to "murali", the container will still think that it is "rickard" so
findByPrimaryKey("rickard") will return it, which is wrong from your
point of view since it really contains "murali". I'm not even sure how
the CMP code will react to the fact that there is now row in the
database corresponding to "murali". Probably nothing will happen and
"rickard" will be read from the database in the next transaction.
It will not work. Give it up.
> I'd really appreciate a clarification on this topic, as I'm not sure the
> spec enforces or even suggests any behavior wrt the Primary key fields.
It doesn't, but since this obviously can be misinterpreted as a
possibility to actually do it this should perhaps be explicitly
prohibited.
/Rickard
--
Rickard Öberg
@home: +46 13 177937
Email: [EMAIL PROTECTED]
Homepage: http://www-und.ida.liu.se/~ricob684
===========================================================================
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".