ObjectWeb Consortium
Search ObjectWeb Mail Archive: 

Advanced Search - Powered by Google


Mail Archive Home | enhydra List | September 2000 Index

<--  Date Index  --> <--  Thread Index  -->

RE: Enhydra: DODS/PostgreSQL and the serial datatype


Nathan,

Suppose you do accomplish what you describe: how do you propose to
synchronize the state of your DO with the value in the database?  By
executing a select to find out the ID you just inserted?  Whoops! There goes
the efficiency you just worked so hard to create.

That said, if you MUST do this, you could look into one of the following
options:

1. hack the generated DO code (ugh)
2. subclass the generated DO code (I do not know if this is possible, but it
ought to be and it's better than #1)
3. write a stored procedure that pulls an ID out of a postgres sequence
(which is what `serial' uses, under the covers), and install it as a BEFORE
INSERT trigger on your table so that it can replace `0' with the sequence
value.

Disclaimer: I have done none of these for the reasons stated in the first
paragraph.

Eric

-----Original Message-----
From: Nathan [mailto:nfrund@xxxxxxxxxx]
Sent: Tuesday, September 26, 2000 10:01 AM
To: enhydra@xxxxxxxxxxx
Subject: Enhydra: DODS/PostgreSQL and the serial datatype


I'm writing an app that requires a database field to be incremented so
that the record can be identified by the unique field.  The problem is
that DODS doesn't understand what the PostgreSQL datatype 'serial' is
and instead of leaving it alone it tries to insert a 0 into the id
field.  The first insert works because 'id' is set to 0 but on
subsequent inserts the id field is not incremented (left at 0) and I get
this message:

        java.sql.SQLException: Failed to insert/update DO: ERROR:
Cannot insert a duplicate key into unique index article_id_key

Has anyone else run into this problem?  How can I make the DataObject
leave the field alone so that the DB can do its thing?  If I use
straight JDBC it works like a charm but I really want to stick with the
abstraction that a DataObject gives me.  It has already been a real life
saver.

I know I can handle  incrementing the field in a PO but I don't want to
because I figure that letting the database handle the work would be more
efficient.  If I'm wrong please let me know.

TIA,

nathan

----------------------------------------------------------------------------
-
To unsubscribe from this mailing list, send email to majordomo@xxxxxxxxxxx
with the text "unsubscribe enhydra" in the body of the email.
If you have other questions regarding this mailing list, send email to
the list admin at owner-enhydra@xxxxxxxxxxxx
-----------------------------------------------------------------------------
To unsubscribe from this mailing list, send email to majordomo@xxxxxxxxxxx
with the text "unsubscribe enhydra" in the body of the email.
If you have other questions regarding this mailing list, send email to
the list admin at owner-enhydra@xxxxxxxxxxxx




<--  Date Index  --> <--  Thread Index  -->

Reply via email to:

Powered by MHonArc.

Copyright © 1999-2005, ObjectWeb Consortium | contact | webmaster.