Re: EOF inserts PK automatically
Re: EOF inserts PK automatically
- Subject: Re: EOF inserts PK automatically
- From: "Ruenagel, Frank" <email@hidden>
- Date: Fri, 12 Nov 2004 12:20:47 +0100
> -----Original Message-----
> From: Sako! [mailto:email@hidden]
> Sent: Friday, November 12, 2004 11:27 AM
> To: Ruenagel, Frank; email@hidden
> Cc: Marek Wawrzyczny
> Subject: Re: EOF inserts PK automatically
>
>
>
> ----- Original Message -----
> From: "Ruenagel, Frank" <email@hidden>
> To: <email@hidden>
> Cc: "Marek Wawrzyczny" <email@hidden>; <email@hidden>
> Sent: Wednesday, November 10, 2004 6:39 PM
> Subject: RE: EOF inserts PK automatically
>
>
> > > -----Original Message-----
> > > From: Sako! [mailto:email@hidden]
> > > Sent: Monday, November 08, 2004 1:05 PM
> > > To: Marek Wawrzyczny
> > > Cc: email@hidden
> > > Subject: Re: EOF inserts PK automatically
> > >
> > >
> > >
> > > ----- Original Message -----
> > > From: "Marek Wawrzyczny" <email@hidden>
> > > To: "Sako!" <email@hidden>
> > > Cc: <email@hidden>; "Chuck Hill"
> > > <email@hidden>
> > > Sent: Monday, November 08, 2004 1:59 AM
> > > Subject: Re: EOF inserts PK automatically
> > >
> > >
> > > >
> > > > On 06/11/2004, at 23:10, Sako! wrote:
> > > >
> > > > >>> before i call EC.SaveChanges(). another Application
> has already
> > > > >>> inserted a row in the Table with the same PK. after
> > > that WO tries to
> > > > >>> insert row with invalid PK.
> > > > >>> this problem is also explaind in the WO documentation
> > > unfortunately
> > > > >>> without really good solution :(
> > > > >>>
> > > > >> I don't know where you got that, its wrong. The real PK
> > > is generated
> > > > >> during save changes as part of a transaction. There is
> > > no danger of
> > > > >> duplication. PK numbers can be skipped but never
> duplicated.
> > > > >>
> > > > > I think i miss something or something is here wrong.
> > > > > When i don t set the PK as a ClassProperty, EOF creates
> > > its own table
> > > > > "EO_PK_TABLE" in the database, and saves the last PK
> in the column
> > > > > pk.
> > > > > Another applications like ACCESS (what i really have
> as another
> > > > > application) for example do not use this technique.
> > > > >
> > > > > let me give an example:
> > > > > 1. EOF adds a row with the PK "27", and CHANGES the pk
> > > column in
> > > > > the table EO_PK_TABLE to "27"
> > > > > 2. ACCESS adds a row with the PK "28".
> > > > > 3. EOF does not mention what happens to the table and
> pk. tries to
> > > > > write with a PK "28" <== which is already used.
> > > > >
> > > > > Mr. Chuck, i know you are experienced developer here, but
> > > I am sure
> > > > > what I am telling you and its 100% correct.
> > > > >
> > > > > I cant change ACCESS now. its expensive and complicated.
> > > > > WO must be flexible with the database and ACCESS.
> > > > > So I thought I use the database itself.
> > > > > There is a feature in MS-SQL <IDENTITY>, what ALWAYS
> allows the
> > > > > database to create the PK automatically.
> > > > > The problem is, this works only if all applications
> never try to
> > > > > write in the PK column.
> > > > > Its possible and easy to make ACCESS stop write in the PK
> > > column. And
> > > > > now my question: "how can i make EOF stop inserting the PK?"
> > > > >
> > > > > This PK conflict is even in the WO books a big problem,
> > > even Apple has
> > > > > no good suggestion for that.
> > > > > If you have any suggestions for me please let me know.
> > > >
> > > > Actually as far as I can tell, the EO_PK_TABLE is not
> the table that
> > > > WebObjects uses to get the next PK. It's easy to test this. On a
> > > > development (not your production) database, start up your
> > > application,
> > > > create some records in a table of your choice (either
> > > through another
> > > > application or through the database) and don't update the
> > > EO_PK_TABLE.
> > > > EOF will still generate records with the correct PK. In
> fact you can
> > > > drop the entire EO_PK_TABLE table altogether and WebObjects
> > > will still
> > > > happily create it and keep on working.
> > > >
> > > > I am not sure what EOF needs EO_PK_TABLE for, but it does
> > > not seem to
> > > > need it for the generation of PKs. I remember reading on
> > > Omnigroup that
> > > > EOF always gets the max() value on the PK column prior
> to generating
> > > > the PK. You are always guaranteed to get a unique PK for
> > > your records.
> > > >
> > > Wrong. Make a test.
> >
> > Well, it is quarter true. ;-)
> > If EOF uses the standard-mechanism of PK-Generation as it
> is implemented
> > in the jdbc-adaptor:
> > EOF uses EO_PK_Table if it exists. If EO_PK_Table is not there,
> > it will be rebuild on demand. And "demand" means: insert a new row.
> > If the table-name of a table in which a new pk should be
> inserted is not
> > listed in the EO_PK_TABLE-table, the correspondig row in
> EO_PK_TABLE will
> be
> > created.
> > In this case EOF uses a max(pk)-query.
> > This means: EOF works fine without EO_PK_Table. Deleting
> lines in the
> table
> > or
> > dropping the whole table does not affect functionality.
>
> what will i change if i drop the Table? EOF will create it
> again? should i
> drop it everyday you mean?
> This means: do you have any idea HOW to drop the table and
> force EOF to dont
> recreate it?
>
> pease.
I have simply dropped the EO_PK_Table-table manually (or deleted rows from
it)
while a project was running on a test database. That's all.
With MS-SQL_Enterprise-Manager it is rather simple to create a
test database as a copy of a 'normal' project. I guess:3 mouse-clicks?
I would not recommend to drop the EO_PK_TABLE-table in the normal workflow,
since an exception is thrown before EOF recreates the EO_PK_TABLE.
I do *not* mean, that you should drop it every time. Strange idea....
My aim was just to clarify the behaviour of the standard
pk-generation mechanism of the jdbc-adaptor. And this mechanism
is (wonderful) robust.
For your problem with the "identity"-column there is no simple solution
out-of-the-box. There were many hints and ideas posted. It depends
on your needs, what's the best for you: How many tables use identity
columns? How flexible and tranparent should the mechanism be?
How important is the database-independence of the WO-App?
Etc.
>
> > I have tested this with the ms-sql-adaptor, which uses the default
> > implementation
> could you send me your test project please ? or at lease the
> java code?
There is no special code, no magic.
>
> > of pk-generation.
> >
>
> pease.
>
> Sako.
>
>
> > >
> > > > I think what you're asking for is how to stop WebObjects
> > > from trying to
> > > > generate the PK and make it use the SQL auto-increment
> > > feature... and
> > > > the answer is, you cannot.
> > > bad for me :)
> > >
> > > >
> > > >
> > > > Marek Wawrzyczny
> > > >
> > > > software engineer
> > > > -------------------------->
> > > > ish group pty ltd
> > > > http://www.ish.com.au
> > > > 7 Darghan St Glebe 2037 Australia
> > > > phone +61 2 9660 1400 fax +61 2 9660 7400
> > > >
> > > >
> > > >
> > >
> >
> >
> >
>
_______________________________________________
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