Laurence Gellert <geller..arkwing.uoregon.edu> wrote:
> > You have to know what the primary key value is before you can insert the
> record.
>
> I won't know the next value until postgres assigns it though a
> mini-transaction it does during the insert. I just want it to be a unique
> number. Building a manual PK handler feels like reinventing the wheel, it
> runs slower, and has opportunity to loose database key integrity.
>
> So, why does Cayenne require us to build our own primary key management
> system?
When I say "You have to know", I mean the application you write plus
cayenne, not you the programmer. Cayenne does handle this for you
automatically. I explained how it did this in an earlier message.
> Running a statement like: INSERT INTO login (username, password) VALUES
> ('test', 'abc'); and letting the database set the next value for LoginID
of
> serial type should be simple.
a) Only if the database supports such a methodology.
b) Getting the primary key back into cayenne with such a methodology would
NOT be simple. Once you inserted the record, you couldn't further update it
since you no longer have a unique identifier to reference it by.
> Is there a way to bypass the AUTO_PK_TABLE behavior and have Cayenne
ignore
> the PK field for the add method? All I need is a one way ticket to insert
> data into the database. Using the object model already setup is way
better
> than writing an INSERT statement. How are people out there handling this
> issue?
>
> Can somebody give me an example of how they implemented AUTO_PK_TABLE
> behavior in postgres?
If postgres has a specific non-standard way to automatically generate
primary keys, you can certainly contribute a class to Cayenne so that it
properly uses that proprietary methodology for Postgres. I added such a
mechanism for OpenBase. I just copied and modified the existing Oracle
sequencing code.
The default cross-database mechanism also works fine, however. The only
reason not to use it is if the proprietary method will offer you better
performance. Generally, this is NOT going to be much of an improvement in
terms of round-trips (based on Oracle/OpenBase) since such methods still
require that you first prefetch a set of valid primary keys, then do another
insert. The only thing that such proprietary methods give you is the
ability to have non-cayenne applications use the same primary key generation
scheme as your cayenne applications.
-Mike
This archive was generated by hypermail 2.0.0 : Mon Aug 02 2004 - 17:04:32 EDT