title: Spring Boot with Hibernate generating drop constraint errors on startup with H2 database
body: <p>I am using spring-boot and have an H2 database configured like so (in the application.properties).</p>
  
  <pre><code>spring.datasource.url=jdbc:h2:mem:AZ;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
  spring.datasource.driverClassName=org.h2.Driver
  spring.datasource.username=sa
  spring.datasource.password=
  spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
  </code></pre>
  
  <p>In the logs I am seeing the following errors:</p>
  
  <pre><code>o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
          name: default
          ...]
  org.hibernate.Version                    : HHH000412: Hibernate Core {4.3.5.Final}
  org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
  org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
  o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
  org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
  o.h.h.i.ast.ASTQueryTranslatorFactory    : HHH000397: Using ASTQueryTranslatorFactory
  org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export
  org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table key_request drop constraint FK_53shrbc21c25inskpp1yoxxss if exists
  org.hibernate.tool.hbm2ddl.SchemaExport  : Table "KEY_REQUEST" not found; SQL statement:
      alter table key_request drop constraint FK_53shrbc21c25inskpp1yoxxss if exists [42102-178]
  </code></pre>
  
  <p>Even though hibernate reports these as errors, I can then login to the H2 console and see the constraints and they appear to be just fine.</p>
  
  <pre><code>SELECT TABLE_NAME, INDEX_NAME, COLUMN_NAME, INDEX_TYPE_NAME FROM information_schema.indexes WHERE TABLE_NAME='KEY_REQUEST';
  TABLE_NAME    INDEX_NAME                            COLUMN_NAME  INDEX_TYPE_NAME  
  KEY_REQUEST   PRIMARY_KEY_F                         REQUEST_ID   PRIMARY KEY
  KEY_REQUEST   FK_53SHRBC21C25INSKPP1YOXXSS_INDEX_F  USER_ID      INDEX
  </code></pre>
  
  <p>If really looks like hibernate is trying to drop these constraints before it actually creates the database (i.e. some kind of bug in hibernate).
  Is there any way to avoid these errors clogging up the logs or are the indicative of a real failure somewhere?</p>
  
  <h2>UPDATE 1</h2>
  
  <p>Trying to force the application to only do updates using this setting:</p>
  
  <pre><code>spring.jpa.hibernate.ddl-auto=update
  </code></pre>
  
  <p>Results in the following errors (all the other errors disappear):</p>
  
  <pre><code>org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000388: Unsuccessful: alter table lti_result add constraint FK_1cnh9amy5br8owkmafsrth3as foreign key (result_id) references lti_link
  org.hibernate.tool.hbm2ddl.SchemaUpdate  : Constraint "FK_1CNH9AMY5BR8OWKMAFSRTH3AS" already exists; SQL statement: 
      alter table lti_result add constraint FK_1cnh9amy5br8owkmafsrth3as foreign key (result_id) references lti_link [90045-178]
  </code></pre>
  
  <p>NOTE: the source is here: <a href="https://github.com/azeckoski/lti_starter" rel="noreferrer">https://github.com/azeckoski/lti_starter</a></p>
  
  <p>Specifically the config:
  <a href="https://github.com/azeckoski/lti_starter/blob/master/src/main/resources/application.properties" rel="noreferrer">https://github.com/azeckoski/lti_starter/blob/master/src/main/resources/application.properties</a></p>
  
  <p>and the model:
  <a href="https://github.com/azeckoski/lti_starter/tree/master/src/main/java/ltistarter/model" rel="noreferrer">https://github.com/azeckoski/lti_starter/tree/master/src/main/java/ltistarter/model</a></p>