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 :)
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.
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 …
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).
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.
try to set the initialize-schema to always:
spring.session.jdbc.initialize-schema: always
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With