RE: EOF inserts PK automatically
RE: EOF inserts PK automatically
- Subject: RE: EOF inserts PK automatically
- From: "Clark, Igor" <email@hidden>
- Date: Thu, 4 Nov 2004 17:10:06 -0000
Incidentally, I'm given to understand one should always insert
EOs into an editing context immediately upon creation and before modifying their values, as not doing so can cause serious
headaches.
I tend to use EOUtilities.createAndInsertInstance(EOEditingContext ec,
String entityName) as it does exactly that - creates and inserts an object into
your EC in one line without having to worry about EOClassDescription and all
that
business.
Good
luck
Igor
Sako
That
would be aganst the very nature of WebObjects. EOF references objects
internally using a global ID which is based on the primary key of the database
row matching the object. If you let your database create the primary key
during the transaction which inserts the new row, WebObjects would not know
the generated key. Moreover with the primary key generated only this late in
the process, WebObjects would not know the value of the foreign key to use by
other rows to reference the newly created one.
That
said, WebObjects relies on the database for providing the primary key it used.
It just ask for it earlier than what you are aiming for.
Pierre
Hello,
i create an object and insert it in the ec, and
fire save changes with this simple code
my table has {(id as PK ),(name)}
EOClassDescription classDescriptionAFDetails =
EOClassDescription.classDescriptionForEntityName( "Test2");
EOGenericRecord newTest2Object = (EOGenericRecord)
classDescriptionAFDetails.createInstanceWithEditingContext( null, null);
newTest2Object.takeValueForKey( "name
", "name");
session.defaultEditingContext().insertObject(newTest2Object);
session.defaultEditingContext().saveChanges();
EOF adds the PK automatically.
i use MS-SQL server and it supports adding the PK
also. this mean i just need to add the name with sql like this
INSERT INTO test2 (name) VALUES ("my new name");
what i look for is, i would like to use the
feature from the db. to do that i have to prvent EOF to add the PK
automatically.
do i have chance to do that?
thanks.
sako
********************************************************************** This
email and any files transmitted with it are intended solely for the use of
the individual or entity to whom they are addressed. If you have received
this email in error please notify the sender of this message.
(email@hidden) This email message has been checked for the
presence of computer viruses; however this protection does not ensure this
message is virus free. Banque centrale du Luxembourg; Tel ++352-4774-1;
http://www.bcl.lu **********************************************************************
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden