Re: Cannot update primary key
Re: Cannot update primary key
- Subject: Re: Cannot update primary key
- From: Art Isbell <email@hidden>
- Date: Mon, 25 Nov 2002 17:22:44 -1000
On Monday, November 25, 2002, at 03:24 PM, Serge SMADJA wrote:
I'm trying to use D2W (WO 5.2/Openbase) on a small database I've
generated from EOModeler. As long as my entities had integer primary
keys, everything worked well. Then, I added a table with a varchar
primary key which I made "visible". I can insert a new record in
database but I cannot modify the primary key attribute without getting
this error :
java.lang.IllegalStateException: cannot update primary-key
'myprimarykey' from '78439439700011' to '78787878787878' on object ...
What should I do to make this attribute writeable ? Looks like a
common pitfall for WebObjects newbies but all the examples have hidden
integer primary keys :(
The examples all use hidden (non-class property) integer attributes as
primary keys for good reasons. Hidden, meaningless integer primary
keys are preferred over varchar primary keys that contain meaningful
data. Because you want to be able to update this varchar attribute, it
should not be the primary key. Instead, place a unique constraint on
it and define a hidden, meaningless integer primary key.
Consider the consequences of defining a mutable attribute as a primary
key when the database will be accessed by various database client
processes. Many of these database clients identify a database row by
its primary key (WebObjects is one of these clients). When you allow
the primary key to be updated, all processes except the one performing
the update will no longer have a way to identify this database row.
This is bad, so always use hidden integer primary and foreign keys that
don't contain meaningful data.
Art
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.