Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Spring JDBC SPRING_SESSION table doesn't exist

I am developing a simple RESTfull service in Java Spring and using JDBCTemplate.

However, I am getting a run time error, which I don't understand. It complains about SPRING_SESSION table not existing, however I think Spring should be able to create necessary tables as needed.

application.properties:

spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:mysql://localhost:3306/getfit?useSSL=false
spring.datasource.username=root
spring.datasource.password=***

Exception:

org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [DELETE FROM SPRING_SESSION WHERE EXPIRY_TIME < ?]; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'getfit.SPRING_SESSION' doesn't exist
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:235) ~[spring-jdbc-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) ~[spring-jdbc-5.0.4.RELEASE.jar:5.0.4.RELEASE]

Exception is triggered by some process attempting to delete record from table which doesn't exist.

Manually creating the table leads to more errors (not existing columns). Setting

hibernate.ddl-auto=update

also doesn't help.

Additionally, I have modified MySQL configuration to allow upper case characters and this also did not help.

Interestingly enough, this issue happened after I formatted my OS and cloned project from github. Before everything was working fine.

Do you have any ideas what could go wrong? Let me know if you need me to show you some code.

Thanks for looking in to this :)

like image 320
Jeremi Avatar asked Apr 22 '18 09:04

Jeremi


People also ask

How to add spring-session-JDBC to a standard spring project?

First, if we’re adding spring-session-jdbc to a standard Spring project, we’ll need to add spring-session-jdbc and h2 to our pom.xml (last two dependencies from the snippet in the previous section). 4.2. Spring Session Configuration Now let’s add a configuration class for Spring Session JDBC: As we can see, the differences are minimal.

Why does spring session throw an error when the required table?

Show activity on this post. Show activity on this post. Spring session creates a table to store sessions in the database. Since the required table doesn't exist it throws the error. Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question. Provide details and share your research! But avoid …

Should spring be able to create tables when they don't exist?

It complains about SPRING_SESSION table not existing, however I think Spring should be able to create necessary tables as needed. Exception is triggered by some process attempting to delete record from table which doesn't exist. Manually creating the table leads to more errors (not existing columns).

What is session management in Spring Boot?

In a web application, user session management is crucial for managing user state. Spring Session is an implementation of four approaches, storing session data in a persistent data store. Spring Session supports multiple datastores, like RDBMS, Redis, HazelCast, MongoDB, etc., to save the user session data.


2 Answers

try to set the initialize-schema to always:

spring.session.jdbc.initialize-schema: always
like image 188
BaDr Amer Avatar answered Sep 17 '22 11:09

BaDr Amer


Spring session creates a table to store sessions in the database. Since the required table doesn't exist it throws the error.

Here's a link you can refer

https://sivalabs.in/2018/02/session-management-using-spring-session-jdbc-datastore/

like image 29
Rahul Avatar answered Sep 20 '22 11:09

Rahul