title: Spring-Session is not creating tables SPRING_SESSION and SPRING_SESSION_ATTRIBUTES on its own, but when I create them manually it throws error
body: <p>Following error comes when I try to enter login information:</p>
  
  <p>PreparedStatementCallback; bad SQL grammar [INSERT INTO SPRING_SESSION_ATTRIBUTES(SESSION_ID, ATTRIBUTE_NAME, ATTRIBUTE_BYTES) VALUES (?, ?, ?)]; nested exception is java.sql.BatchUpdateException: Unknown column 'SESSION_ID' in 'field list'</p>
  
  <p>Following query I ran:</p>
  
  <pre><code>CREATE TABLE 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 SPRING_SESSION_PK PRIMARY KEY (PRIMARY_ID)
  ) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
  
  CREATE UNIQUE INDEX SPRING_SESSION_IX1 ON SPRING_SESSION (SESSION_ID);
  CREATE INDEX SPRING_SESSION_IX2 ON SPRING_SESSION (EXPIRY_TIME);
  CREATE INDEX SPRING_SESSION_IX3 ON SPRING_SESSION (PRINCIPAL_NAME);
  
  CREATE TABLE SPRING_SESSION_ATTRIBUTES (
      SESSION_PRIMARY_ID CHAR(36) NOT NULL,
      ATTRIBUTE_NAME VARCHAR(200) NOT NULL,
      ATTRIBUTE_BYTES BLOB NOT NULL,
      CONSTRAINT SPRING_SESSION_ATTRIBUTES_PK PRIMARY KEY (SESSION_PRIMARY_ID, ATTRIBUTE_NAME),
      CONSTRAINT SPRING_SESSION_ATTRIBUTES_FK FOREIGN KEY (SESSION_PRIMARY_ID) REFERENCES SPRING_SESSION(PRIMARY_ID) ON DELETE CASCADE
  ) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
  </code></pre>
  
  <p>Following is my SpringConfig.java</p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  @EnableGlobalMethodSecurity(prePostEnabled=true)
  @EnableJdbcHttpSession
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
      @Autowired
      private Environment env;
  
      @Autowired
      private UserSecurityService userSecurityService;
  
       @Bean
          public HttpSessionStrategy httpSessionStrategy() {
              return new HeaderHttpSessionStrategy();
          }
  
      private BCryptPasswordEncoder passwordEncoder() {
          return SecurityUtility.passwordEncoder();
      }
  
      private static final String[] PUBLIC_MATCHERS = {
              "/css/**",
              "/js/**",
              "/image/**",
              "/newUser",
              "/forgetPassword",
              "/login",
              "/fonts/**"
      };
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http
              .authorizeRequests().
          /*  antMatchers("/**").*/
              antMatchers(PUBLIC_MATCHERS).
              permitAll().anyRequest().authenticated()
              .and().requestCache().requestCache(new NullRequestCache())
              .and()
              .httpBasic();
          http
              .csrf().disable().cors().disable()
              .formLogin().failureUrl("/login?error")
              .defaultSuccessUrl("/")
              .loginPage("/login").permitAll()
              .and()
              .logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
              .logoutSuccessUrl("/?logout").deleteCookies("remember-me").permitAll()
              .and()
              .rememberMe();
      }
  
      @Autowired
      public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
          auth.userDetailsService(userSecurityService).passwordEncoder(passwordEncoder());
          auth.inMemoryAuthentication().withUser("admin").password("admin").roles("ADMIN");
      }
  </code></pre>
  
  <p>Insert command fails and thus i am not able to login to my spring boot app</p>
  
  <p>After I change field To SESSION_ID:</p>
  
  <pre><code>SQL [INSERT INTO SPRING_SESSION_ATTRIBUTES(SESSION_ID, ATTRIBUTE_NAME, ATTRIBUTE_BYTES) VALUES (?, ?, ?)]; Cannot add or update a child row: a foreign key constraint fails (`api_emailer1x`.`SPRING_SESSION_ATTRIBUTES`, CONSTRAINT `SPRING_SESSION_ATTRIBUTES_FK` FOREIGN KEY (`SESSION_ID`) REFERENCES `SPRING_SESSION` (`PRIMARY_ID`) ON DELETE CASCADE); nested exception is java.sql.BatchUpdateException: Cannot add or update a child row: a foreign key constraint fails (`api_emailer1x`.`SPRING_SESSION_ATTRIBUTES`, CONSTRAINT `SPRING_SESSION_ATTRIBUTES_FK` FOREIGN KEY (`SESSION_ID`) REFERENCES `SPRING_SESSION` (`PRIMARY_ID`) ON DELETE CASCADE)
  </code></pre>
  
  <p>Now I am running following sql:</p>
  
  <pre><code>CREATE TABLE 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 SPRING_SESSION_PK PRIMARY KEY (PRIMARY_ID)
  ) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
  
  CREATE UNIQUE INDEX SPRING_SESSION_IX1 ON SPRING_SESSION (SESSION_ID);
  CREATE INDEX SPRING_SESSION_IX2 ON SPRING_SESSION (EXPIRY_TIME);
  CREATE INDEX SPRING_SESSION_IX3 ON SPRING_SESSION (PRINCIPAL_NAME);
  
  CREATE TABLE SPRING_SESSION_ATTRIBUTES (
      SESSION_PRIMARY_ID CHAR(36) NOT NULL,
      ATTRIBUTE_NAME VARCHAR(200) NOT NULL,
      ATTRIBUTE_BYTES BLOB NOT NULL,
      CONSTRAINT SPRING_SESSION_ATTRIBUTES_PK PRIMARY KEY (SESSION_PRIMARY_ID, ATTRIBUTE_NAME),
      CONSTRAINT SPRING_SESSION_ATTRIBUTES_FK FOREIGN KEY (SESSION_PRIMARY_ID) REFERENCES SPRING_SESSION(SESSION_ID) ON DELETE CASCADE
  ) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
  </code></pre>
  
  <p>Now the issue is When I try to login in my spring boot application it comes back to same login page </p>
  
  <p>And SESSION and SESSION_ATTRIBUTES are getting inserted in db. I dont understand this behaviour</p>
  
  <hr>