Unsuccessful: alter table XXX drop constraint YYY in Hibernate/JPA/HSQLDB standalone

后端 未结 6 1522
忘掉有多难
忘掉有多难 2020-12-04 12:13

I am trying to run some Hibernate/JPA examples using an in-memory HSQL DB. The error message I get is the following:

13:54:21,427 ERROR SchemaExport:425 - HH         


        
6条回答
  •  一整个雨季
    2020-12-04 13:05

    The Solution @Sander provided above works for MYSQL too. Just extend MySQL5InnoDBDialect instead like below:

    import org.hibernate.dialect.MySQL5InnoDBDialect;
    
    public class ImprovedMySQLDialect extends MySQL5InnoDBDialect {
        @Override
        public String getDropSequenceString(String sequenceName) {
            // Adding the "if exists" clause to avoid warnings
            return "drop sequence if exists " + sequenceName;
        }
    
        @Override
        public boolean dropConstraints() {
            // We don't need to drop constraints before dropping tables, that just leads to error
            // messages about missing tables when we don't have a schema in the database
            return false;
        }
    }
    

    Then in your datasource file change the following line:

    dialect = org.hibernate.dialect.MySQL5InnoDBDialect
    

    to

    dialect = my.package.name.ImprovedMySQLDialect
    

提交回复
热议问题