You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Thomas Dudziak <to...@first.gmd.de> on 2004/04/06 12:58:07 UTC
Re: OJB possible bug when using automatical assignment of unique
values on Postgres
On Tue, 6 Apr 2004, Martin I. Levi wrote:
> Hello,
>
> Having seen there are a few Postgres users out there it may be
> interesting to comment a problem we had here.
> First of all the software versions we are using are the following:
>
> PostgreSQL 7.2.1
> OJB 1.0.rc.5
>
> On a Debian Linux platform.
>
> The problem is related to sequences. When we configure OJB to assign
> unique values for primary keys and we perform a query like this one:
>
> "select rows from our_table" (through OJBs ODMG implementation)
>
> the correct results are shown but a new row is INSERTED in the table
> being this row a copy of the first row (id=0) with a new id.
> Now, if we perform a the following query:
>
> "select rows from our_table where id=0" (always through OJBs ODMG
> implementation)
>
> Instead of getting the row with id=0, a new row with a new ID is shown.
> This row, which is an exact copy of the row we wanted with a new id, is
> also inserted by OJB in our table.
>
> If we dont perform querys which include the ID=0 row as a result
> everything works fine. We really do not use this OJB feature and we
> discovered this testing. This bug caused all our application to die
> because in our original table definition one of the columns (not the ID
> column) was UNIQUE and OJB tried to insert a row with this column
> duplicated.
You don't specify a sequence manager (high-low is the default if I'm not
mistaken which means that OJB generates the pk value independent from the
database), and the Product.id field is autoincrement, but you also have in
the database the corresponding column as SERIAL (which means autoincrement
on the database side).
You could try using the SequenceManagerNativeImpl in which case you should
also specify the Product.id field as access='readonly'.
Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
OJB possible bug when using automatical assignment ... The PRIMARY
KEY IS INTEGER NOT SERIAL
Posted by "Martin I. Levi" <ml...@labtie.mmt.upc.es>.
On Tue, 2004-04-06 at 12:58, Thomas Dudziak wrote:
> You don't specify a sequence manager (high-low is the default if I'm not
> mistaken which means that OJB generates the pk value independent from the
> database), and the Product.id field is autoincrement, but you also have in
> the database the corresponding column as SERIAL (which means autoincrement
> on the database side).
> You could try using the SequenceManagerNativeImpl in which case you should
> also specify the Product.id field as access='readonly'.
>
> Tom
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
Oh, excuse me, I sent the wrong sql script. The db creation script is
the following:
---- begining create_db_noseq.sql ----
CREATE TABLE product(
id INTEGER PRIMARY KEY,
name VARCHAR(50),
price DECIMAL(12,5),
stock INTEGER
);
INSERT INTO product (id,price,name,stock) VALUES (0, 5.4, 'Conflictive
Product', 3);
INSERT INTO product (id,price,name,stock) VALUES (1, 5.99, 'video', 9);
INSERT INTO product (id,price,name,stock) VALUES (2, 8.43, 'car', 400);
INSERT INTO product (id,price,name,stock) VALUES (3, 25.3, 'house', 8);
INSERT INTO product (id,price,name,stock) VALUES (4, 3.8, 'computer',
3000);
INSERT INTO product (id,price,name,stock) VALUES (5, 87.46, 'book',
100);
INSERT INTO product (id,price,name,stock) VALUES (6, 9.4, 'printer', 4);
INSERT INTO product (id,price,name,stock) VALUES (7, 7.29, 'television',
6);
INSERT INTO product (id,price,name,stock) VALUES (8, 20.3, 'window',
10);
---- end create_db_noseq.sql ----
Anyway it fails in both cases (SERIAL or INTEGER) in the same way.
We have already solve this problem using SequenceManagerNextValImpl and
it works well (*). We dont use OJB to provide sequences so we really
dont have a need to solve the core problem, im just reporting this issue
because it came across our way.
(*) The problems we had before were a configuration issue.
Greets,
Martin Ivan Levi
Universitat Politecnica de Catalunya
Centre Tecnologic de Transferencia de Calor
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org