title: ERROR: duplicate key value violates unique constraint "spring_session_attributes_pk"\n Detail: Key (session_primary_id, attribute_name)
body: <p>Currently, I'm using:</p>
  <ul>
  <li>Spring boot 2.2.2</li>
  <li>Spring jdbc 2.5.0</li>
  <li>Spring core 2.5.0</li>
  </ul>
  <p>Sometimes, I got errors when accessing my endpoints, here is the stack trace, this happen after upgrading my library from:</p>
  <ul>
  <li>spring boot 2.1.7</li>
  <li>spring jdbc 2.1.8</li>
  <li>spring core 2.1.8</li>
  </ul>
  <p>Handle DataIntegrityViolationException: PreparedStatementCallback;</p>
  <pre><code>SQL [INSERT INTO SPRING_SESSION_ATTRIBUTES(SESSION_PRIMARY_ID, ATTRIBUTE_NAME, ATTRIBUTE_BYTES) SELECT PRIMARY_ID, ?, ? FROM SPRING_SESSION WHERE SESSION_ID = ?];
  ERROR: duplicate key value violates unique constraint \&quot;spring_session_attributes_pk\&quot;
      Detail: Key (session_primary_id, attribute_name)=(a9427ef5-92a4-4845-8769-e034c3b50b70, SPRING_SECURITY_CONTEXT) already exists.; nested exception is org.postgresql.util.PSQLException: 
  
  ERROR: duplicate key value violates unique constraint \&quot;spring_session_attributes_pk\&quot;
      Detail: Key (session_primary_id, attribute_name)=(a9427ef5-92a4-4845-8769-e034c3b50b70, SPRING_SECURITY_CONTEXT) already exists.
      org.springframework.dao.DuplicateKeyException: PreparedStatementCallback; SQL [INSERT INTO SPRING_SESSION_ATTRIBUTES(SESSION_PRIMARY_ID, ATTRIBUTE_NAME, ATTRIBUTE_BYTES) SELECT PRIMARY_ID, ?, ? FROM SPRING_SESSION WHERE SESSION_ID = ?]; 
  
  ERROR: duplicate key value violates unique constraint \&quot;spring_session_attributes_pk\&quot;
      Detail: Key (session_primary_id, attribute_name)=(a9427ef5-92a4-4845-8769-e034c3b50b70, SPRING_SECURITY_CONTEXT) already exists.; nested exception is org.postgresql.util.PSQLException:
  
  ERROR: duplicate key value violates unique constraint \&quot;spring_session_attributes_pk\&quot;
      Detail: Key (session_primary_id, attribute_name)=(a9427ef5-92a4-4845-8769-e034c3b50b70, SPRING_SECURITY_CONTEXT) already exists.
      at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:243)
  </code></pre>
  <p>Here is my session tables:</p>
  <pre><code>CREATE TABLE APP_SPRING_SESSION (
          PRIMARY_ID CHAR(36) NOT NULL,
          SESSION_ID CHAR(36) NOT NULL,
          CREATION_TIME BIGINT NOT NULL,
          LAST_ACCESS_TIME BIGINT NOT NULL,
          MAX_INACTIVE_INTERVAL INT NOT NULL,
          EXPIRY_TIME BIGINT NOT NULL,
          PRINCIPAL_NAME VARCHAR(100),
          CONSTRAINT APP_SPRING_SESSION_PK PRIMARY KEY (PRIMARY_ID)
  );
  
  CREATE UNIQUE INDEX APP_SPRING_SESSION_IX1 ON APP_SPRING_SESSION (SESSION_ID);
  CREATE INDEX APP_SPRING_SESSION_IX2 ON APP_SPRING_SESSION (EXPIRY_TIME);
  CREATE INDEX APP_SPRING_SESSION_IX3 ON APP_SPRING_SESSION (PRINCIPAL_NAME);
  
  CREATE TABLE APP_SPRING_SESSION_ATTRIBUTES (
         SESSION_PRIMARY_ID CHAR(36) NOT NULL,
         ATTRIBUTE_NAME VARCHAR(200) NOT NULL,
         ATTRIBUTE_BYTES BYTEA NOT NULL,
         CONSTRAINT APP_SPRING_SESSION_ATTRIBUTES_PK PRIMARY KEY (SESSION_PRIMARY_ID, ATTRIBUTE_NAME),
         CONSTRAINT APP_SPRING_SESSION_ATTRIBUTES_FK FOREIGN KEY (SESSION_PRIMARY_ID) REFERENCES APP_SPRING_SESSION(PRIMARY_ID) ON DELETE CASCADE
  );
  </code></pre>
  <p>Does anyone know how to fix the problem?</p>