title: IntegrationTest isolation fails in springboot 2.2.2.RELEASE (Error dopping tables after each SpringBootTest)
body: <p>Our app is working in 2.0.4 release. After upgrade to 2.2.2.RELEASE we see integration tests failing. I suspect that there is some misconfiguration, and each integration test simply does not clean after itself or there is extra initialization which weren't here before. I really do not know how to fix it properly.</p>
  
  <p>To be specific. Each test works when invoked separately. When executed all of them we do see errors like:</p>
  
  <pre><code>org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "drop table somewhere.sometable if exists" via JDBC Statement
  ...
  caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Cannot drop "SOME_TABLE" because "FKKJEJC7GUX6OTX5NGANQCMN83R, FK7WLRCFA21PY7CI3R4OL1OWODT, FKQPMY4YOVD3D6HBNT0XX92149P, FK1TG6AMM2NSM6UJTO9EJHPJIXY, FKLPTBKDKFCHE72RJ5RRRIH4ORJ" depends on it; SQL statement:
  </code></pre>
  
  <p>and </p>
  
  <pre><code>2019-12-16 21:11:00.075 org.apache.tomcat.util.modeler.Registry  : The MBean registry cannot be disabled because it has already been initialised
  </code></pre>
  
  <p>which suggests me, that we're trying to re-initialize something already initialized + there is wrong order of drops in hibernate initialization. But I really cannot see anything wrong on our side. Lets show some excerpts:</p>
  
  <p>annotations of test:</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @ActiveProfiles(...)
  @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  public class SomeIT {
  </code></pre>
  
  <p>tests are executed via:</p>
  
  <pre><code>&lt;plugin&gt;
    &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
    &lt;artifactId&gt;maven-failsafe-plugin&lt;/artifactId&gt;
    &lt;version&gt;2.22.2&lt;/version&gt;
    &lt;configuration&gt;
      &lt;useSystemClassLoader&gt;false&lt;/useSystemClassLoader&gt;
      &lt;forkCount&gt;0&lt;/forkCount&gt;
      &lt;reuseForks&gt;false&lt;/reuseForks&gt;
    &lt;/configuration&gt;
    &lt;executions&gt;
      &lt;execution&gt;
        &lt;id&gt;integration-test&lt;/id&gt;
        &lt;goals&gt;
          &lt;goal&gt;integration-test&lt;/goal&gt;
        &lt;/goals&gt;
      &lt;/execution&gt;
      &lt;execution&gt;
        &lt;id&gt;verify&lt;/id&gt;
        &lt;goals&gt;
          &lt;goal&gt;verify&lt;/goal&gt;
        &lt;/goals&gt;
      &lt;/execution&gt;
    &lt;/executions&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>and application.properties for tests:</p>
  
  <pre><code>spring.jpa.database=H2
  spring.jpa.hibernate.ddl-auto=create
  spring.jpa.properties.hibernate.jdbc.batch_size=5
  spring.jpa.properties.hibernate.order_inserts=true
  spring.jpa.properties.hibernate.order_updates=true
  spring.jpa.properties.hibernate.jdbc.batch_versioned_data=true
  
  #this disables option to have opened tx in view IIUC. We don't rely on that, so this just removes warning logging from console.
  spring.jpa.open-in-view=false
  
  #used to select db initialization scripts.
  spring.datasource.platform=org.hibernate.dialect.H2Dialect
  
  spring.datasource.url=jdbc:h2:mem:somewhere;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;INIT=create schema if not exists somewhere
  spring.datasource.driver-class-name = org.h2.Driver
  
  #this is probably needed for @DataJpaTest: I have no idea how to configure @DataJpaTest so that it can run with
  #autoconfigured H2 db, probably it's caused by having schema defined in entities. Anyways @DataJpaTest fails to
  #create schema. So alternative is to configure one DB for whole app here, and this option forces all @DataJpaTest not to
  #replace this configuration with autoconfigured db.
  spring.test.database.replace=none
  </code></pre>
  
  <p>Tested changes: </p>
  
  <ul>
  <li>I changed create to create-drop if it helps in any way and no, it
  does not help in any way.</li>
  <li>I tried to @DirtiesContext on class level for every IT test, which is what I'd expect anyways, that context is created/killed with every IT test class, but that did not help either.</li>
  <li>I tried to remove <code>replace=none</code>, but that just kills all unit tests(because schema is not created), and does not help in any way to integration tests.</li>
  </ul>
  
  <p>Current workaround: well all I was able to come up with is not to reuse db. Which with <code>replace=none</code> is possible only via:</p>
  
  <pre><code>spring.datasource.url=jdbc:h2:mem:somewhere${random.uuid};DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;INIT=create schema if not exists somewhere
  </code></pre>
  
  <p>but I deeply hate this "solution". What can cause incorrect db re-initialization / missing cleanups / or what the cause of all this could be?</p>
  
  <p>(edit: if you know better title to this question, please suggest. Thanks).</p>