db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dyre.Tjeldv...@Sun.COM
Subject Re: Generate Always and SQLIntegrityConstraintViolationException
Date Tue, 22 Jan 2008 15:12:22 GMT
Dyre.Tjeldvoll@Sun.COM writes:

> Knut Anders Hatlen <Knut.Hatlen@Sun.COM> writes:
>
>> wbecker <wbecker@gmail.com> writes:
>>
>>> I don't understand how this can be happening, but it is:
>>>
>>> I've created at a table:
>>>
>>> CREATE TABLE Foo (
>>>        id INT NOT NULL GENERATED ALWAYS AS IDENTITY(START WITH 1, INCREMENT
>>> BY 1)
>>>      , PRIMARY KEY (id)
>>> );
>>>
>>> This works fine and I have added some data to it by using:
>>>
>>> INSERT INTO Foo () VALUE (DEFAULT)
>>>
>>> This works fine for a bit, but eventually it stops working and tells me: 
>>> java.sql.SQLIntegrityConstraintViolationException: The statement was aborted
>>> because it would have caused a duplicate key value in a unique or primary
>>> key constraint or unique index identified by 'SQL080122133352260' defined on
>>> 'Foo'.
>>>
>>> How could I possibly have duplicate values if the only way I add to it is by
>>> using the above query in a PreparedStatement?
>>>
>>> Now, I have found a way around it, which seems very dodgy. I can just
>>> recreate the PreparedStatement and then run the insert again and it works. 
>>>
>>> Is this a bug, expected behaviour or am I doing something wrong?
>>
>> This looks like a bug to me. It would be great if you could log a bug
>> report in JIRA (see http://db.apache.org/derby/DerbyBugGuidelines.html
>> for instructions) so that we can keep track of it.
>
> And you might as well check the regression box right away, since it is a
> regression caused by DERBY-827. It works in revision <= 540920.

I'm currently running the tests with the following patch which seems to
fix the repro:

Index: java/engine/org/apache/derby/impl/sql/execute/RowResultSet.java
===================================================================
--- java/engine/org/apache/derby/impl/sql/execute/RowResultSet.java     (revision 614214)
+++ java/engine/org/apache/derby/impl/sql/execute/RowResultSet.java     (working copy)
@@ -183,6 +183,7 @@
                        if (SanityManager.DEBUG)
                                SanityManager.DEBUG("CloseRepeatInfo","Close of RowResultSet
repeated");
 
+        cachedRow = null;
                closeTime += getElapsedMillis(beginTime);
        }


If the tests pass, I'm ready to attach it to a Jira issue.

-- 
dt

Mime
View raw message