Tag Archives: ddl-auto

[Solved] JPA Create Sheet error at the First time: Cant DROP [xxx];check that column/key exists

Main contents of error reporting information:

        Cant DROP [xxx]; check that column/key exists


Error reporting information reference data:

A configuration as follows:

package org.hibernate.tool.schema.internal;

public abstract class AbstractSchemaMigrator implements SchemaMigrator {
    …………

    private UniqueConstraintSchemaUpdateStrategy uniqueConstraintStrategy;
}

The reason for the locking problem is that the default configuration is: delete + first and then create.

Then the solution of the problem should consider using the second one: RECREATE_QUIETLY, try to create it directly and ignore the exception.


Problem-solving:

Configure the above mentioned configuration in application.yml, but since this configuration was not prompted, after a query, it was found in.

package org.hibernate.cfg;


public interface AvailableSettings extends org.hibernate.jpa.AvailableSettings {
    ……
    /*
        In most dialects, unique constraints are used for unique columns and unique keys. SchemaUpdate needs to create these constraints, but DB support for finding existing constraints is extremely inconsistent. In addition, non-explicitly named unique constraints use randomly generated characters. Therefore, choose from these strategies. org.hibernate.tool.hbm2ddl.UniqueConstraintSchemaUpdateStrategy.DROP_RECREATE_QUIETLY (default): Attempt to delete and then (re)create each unique constraint. Ignore any exceptions thrown. org.hibernate.tool.hbm2ddl.UniqueConstraintSchemaUpdateStrategy.RECREATE_QUIETLY : Attempts to (re)create the unique constraint, ignoring any exceptions thrown if the constraint already exists org.hibernate.tool. hbm2ddl.UniqueConstraintSchemaUpdateStrategy.SKIP : Don't try to create unique constraint structure updates
    */
    String UNIQUE_CONSTRAINT_SCHEMA_UPDATE_STRATEGY = "hibernate.schema_update.unique_constraint_strategy";

    ……
}

Configurate in application.yml:

spring:
  ## jpa configuration
  jpa:
    hibernate:
      ddl-auto: ${JPA_HIBERNATE_DDL_AUTO:update}
    open-in-view: ${JPA_OPEN_IN_VIEW:true}
    show-sql: ${JPA_SHOW_SQL:false}
    properties:
      hibernate:
        schema_update:
          ## This configuration is the focus of this blog post, after setting, the error report no longer appears
          unique_constraint_strategy: RECREATE_QUIETLY