title: Spring Boot 2 - H2 Database - @SpringBootTest - Failing on org.h2.jdbc.JdbcSQLException: Table already exists
body: <p>Unable to test Spring Boot &amp; H2 with a script for creation of table using schema.sql.</p>
  
  <p>So, what’s happening is that I have the following properties set:</p>
  
  <pre><code>spring.datasource.driver-class-name=org.h2.Driver
  spring.datasource.initialization-mode=always
  spring.datasource.username=sa
  spring.datasource.password=
  spring.datasource.platform=h2
  spring.datasource.url=jdbc:h2:mem:city;MODE=PostgreSQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
  
  spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
  spring.jpa.generate-ddl=false
  spring.jpa.hibernate.ddl-auto=update
  spring.jpa.show-sql=true
  </code></pre>
  
  <p>and, I expect the tables to be created using the schema.sql. The application works fine when I run <strong>gradle bootRun</strong>. However, when I run tests using <strong>gradle test</strong>, my tests for Repository passes, but the one for my Service fails stating that it’s trying to create the table when the table already exists:</p>
  
  <p>Exception raised:</p>
  
  <pre><code>Caused by: org.h2.jdbc.JdbcSQLException: Table "CITY" already exists;             
  SQL statement:
  CREATE TABLE city ( id BIGINT NOT NULL, country VARCHAR(255) NOT NULL, map VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, state VARCHAR(2555) NOT NULL, PRIMARY KEY (id) ) [42101-196]
  at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
  at org.h2.message.DbException.get(DbException.java:179)
  at org.h2.message.DbException.get(DbException.java:155)
  at org.h2.command.ddl.CreateTable.update(CreateTable.java:117)
  at org.h2.command.CommandContainer.update(CommandContainer.java:101)
  at org.h2.command.Command.executeUpdate(Command.java:260)
  at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:192)
  at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:164)
  at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95)
  at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java)
  at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:471)
  ... 105 more
  </code></pre>
  
  <p>The code is setup and ready to recreate the scenario. README has all the information -> 
  <a href="https://github.com/tekpartner/learn-spring-boot-data-jpa-h2" rel="noreferrer">https://github.com/tekpartner/learn-spring-boot-data-jpa-h2</a></p>