java and postgresql: duplicate key value violation, despite sending none duplicate keys
<p>From what I deduce, it seems that I attempt to insert into my postgresql database a new row, with a new primary key combination. And yet it complains that I insert the same keys several times.</p>

<p>The evidence (from error-log):</p>

<pre><code>ERROR com.saxo.read.postgres.RequestLoggingStore - Unable to insert request correctly, uri: /someUrlHere, uuid: a7813f97-7c0d-4739-b20b-a2a6ab2f32a3, at: 1470137399294243
org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "requestlogging_pkey"
  Detail: Key (id, "timestamp")=(a7813f97-7c0d-4739-b20b-a2a6ab2f32a3, 1470137399294243) already exists.
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2270)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1998)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
        ....
ERROR com.saxo.read.postgres.RequestLoggingStore - Unable to insert request correctly, uri: /someUrlHere, uuid: 1891dc28-64b8-4a16-8d22-67af6a605aa0, at: 1470137399293662
org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "requestlogging_pkey"
  Detail: Key (id, "timestamp")=(a7813f97-7c0d-4739-b20b-a2a6ab2f32a3, 1470137399294243) already exists.
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2270)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1998)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
        ....
</code></pre>

<p>As you can see, PQSL complains that I have a duplicate key violation, at it SHOULD think, if I had given it the values that it complains about. 
<code>(a7813f97-7c0d-4739-b20b-a2a6ab2f32a3, 1470137399294243)</code> is a duplicate key. HOWEVER, as can be seen from my error log in RequestLoggingStore , the uuid and timestamp reported are not the same as those reported by PSQL, and is NOT a duplicate key.</p>

<p>I immediately assumed that I have made a mistake in the code, and that the reported UUID and timestamp is not what I insert into the postgresql database. But I don't see how this is possible from the code below:</p>

<pre><code>public String put(String uri, String method, String body, String headers, String userId) {
        String uuid = null;
        long timestamp = stamper.timestamp();
        try {
            uuid = java.util.UUID.randomUUID().toString();

            insertQuery.setString(1, uri);
            insertQuery.setString(2, body);
            insertQuery.setString(3, method);
            insertQuery.setString(4, headers);
            insertQuery.setString(5, userId);
            insertQuery.setLong(6, timestamp);
            insertQuery.setString(7, uuid);

            insertQuery.execute();
            return uuid;
        } catch (Exception e) {
            logger.error("Unable to insert request correctly, uri: {}, uuid: {}, at: {}", uri, uuid, timestamp, e);
            return null;
        }
    }
</code></pre>

<p>Just in case you want to see the insert query also:</p>

<pre><code>insertQuery = postgresConnection.prepareStatement("INSERT INTO "+TableName+"( "+listOfArgs+" ) VALUES ( ?, ?, ?, ?, ?, ?, ? );");
</code></pre>

<p>UUID should either be null, or the same value as reported by my error logger, correct? </p>

<p>How could there be a difference between the 2?</p>

<p>Did I make a mistake or is there something wrong with java driver for psql? </p>

<p>I am logging all incoming requests to my web service/API. When testing it seems to work fine. Does it become too stressed under high loads? </p>