title: Spring Oauth JWT - Refresh Token
body: <p>So, I have implemented Spring Oauth2 security with JWT token. </p>
  
  <p>I can get the JWT <code>access_tokens</code> but <code>refresh_token</code> usage is what I don't understand fully. I can use the <code>refresh_token</code> to get new <code>access_token</code> and new <code>refresh_token</code>. </p>
  
  <p>When I want to use the new <code>refresh_token</code> again I get the error which says that this token is invalid. If I use old <code>refresh_token</code> then I get the exception <code>DuplicateKeyException, PreparedStatementCallback; SQL [insert into oauth_access_token (token_id, token, authentication_id, user_name, client_id, authentication, refresh_token) values (?, ?, ?, ?, ?, ?, ?)]; ERROR: duplicate key value violates unique constraint "oauth_access_token_pkey"</code> </p>
  
  <p>This is DDL of the <code>oauth_access_token</code> table:</p>
  
  <pre><code>CREATE TABLE oauth_access_token (
      token_id varchar(510) NULL DEFAULT NULL::character varying,
      token bytea NULL,
      authentication_id varchar(510) NOT NULL,
      user_name varchar(510) NULL DEFAULT NULL::character varying,
      client_id varchar(510) NULL DEFAULT NULL::character varying,
      authentication bytea NULL,
      refresh_token varchar(510) NULL DEFAULT NULL::character varying,
      CONSTRAINT oauth_access_token_pkey PRIMARY KEY (authentication_id)
  )
  WITH (
      OIDS=FALSE
  );
  </code></pre>
  
  <p>If I remove the constraint <code>oauth_access_token_pkey</code> then it works fine, but then the the table contains N token rows, instead of 1, and new tokens cant be issued because of the <code>IncorrectResultSizeDataAccessException</code>.</p>
  
  <p>What should I do to make refresh token work?</p>