Unsuccessful: alter table XXX drop constraint YYY in Hibernate/JPA/HSQLDB standalone
You can ignore these errors. Combination of create-drop
and empty (which is the case always for in-memory) database produces these for every database object it tries to drop. Reason being that there is not any database objects to remove - DROP statements are executed against empty database.
Also with normal permanent database such a errors do come, because Hibernate does not figure out before executing DROP statements does added object exist in database or is it new.
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;
}
}
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