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

后端 未结 6 1516
忘掉有多难
忘掉有多难 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 12:47

    This solution worked for me, as opposed to the other solution that's given. Apparently mileages vary.

    This was my exact error:

    HHH000389: Unsuccessful: alter table ... drop constraint FK_g1uebn6mqk9qiaw45vnacmyo2 if exists
    Table "..." not found; SQL statement: ...
    

    This is my solution, overriding the H2 dialect:

    package com.totaalsoftware.incidentmanager;
    
    import org.hibernate.dialect.H2Dialect;
    
    /**
     * Workaround.
     * 
     * @see https://hibernate.atlassian.net/browse/hhh-7002
     * 
     */
    public class ImprovedH2Dialect extends H2Dialect {
        @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;
        }
    }
    

提交回复
热议问题