4

I've set up a Spring Boot MVC application (2.0.5.RELEASE) using Spring Initializr, where I've also included "Session". That just seems to include "implementation('org.springframework.session:spring-session-jdbc')" in my build.grade dependencies, and as I understand it, no additional configuration is necessary. The only thing I've added is a liquibase migration for the required DB tables to support the JDBC-based session. The application boots up and listens on 8080 just fine, but when I hit a controller, I get an error with the following in the debug lines:

21:36:34.903 [QUIET] [system.out] 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 "pk_spring_session_attributes"
21:36:34.903 [QUIET] [system.out]   Detail: Key (session_primary_id)=(e4eba468-b0c0-4561-991b-7da4b83326c9) already exists.; nested exception is org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "pk_spring_session_attributes"
21:36:34.903 [QUIET] [system.out]   Detail: Key (session_primary_id)=(e4eba468-b0c0-4561-991b-7da4b83326c9) already exists.
21:36:34.903 [QUIET] [system.out]       at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:242) ~[spring-jdbc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

I'd appreciate any explanation of why I get this error, when it seems that creating and loading sessions is basic built-in functionality. My guess is that I'll need to add some configuration, but I am not sure what to add and why it seems to half-function without any.

user605331
  • 3,718
  • 4
  • 33
  • 60

0 Answers0