java.lang.UnsupportedOperationException: DROP CONSTRAINT 仅支持 Hibernate

java.lang.UnsupportedOperationException: DROP CONSTRAINT is only supported for Hibernate

我试图在 table 中删除外键约束,但 ucanacess 不支持 SQL "DROP CONSTRAINT" 语句。错误说:

java.lang.UnsupportedOperationException: DROP CONSTRAINT is only supported for Hibernate hbm2ddl.auto "create"

有人知道解决这个问题的方法吗?

private void dropTables() throws SQLException {
        final String RENTALS = "RENTALS";
        Statement statement = conn.createStatement();

        DatabaseMetaData metaData = conn.getMetaData();
        ResultSet rs = metaData.getTables(null, null, RENTALS, null);

        while (rs.next()) {
            if (rs.getString(3).equals(RENTALS)) {
                statement.executeUpdate("ALTER TABLE RENTALS DROP CONSTRAINT"  
                                                           + " custNumber;");
                statement.executeUpdate("ALTER TABLE RENTALS DROP CONSTRAINT" 
                                                           + " vehNumber;");
                statement.executeUpdate("DROP TABLE CUSTOMERS;");
                statement.executeUpdate("DROP TABLE VEHICLE;");
                statement.executeUpdate("DROP TABLE RENTALS;");
            }
        }
}

错误消息暗示将 hbm2ddl.auto 设置为 create 将解决问题:

<entry key="hibernate.hbm2ddl.auto" value="create">

但是,在执行此操作之前您可能需要三思,因为这意味着每次启动应用程序时都会创建和删除与您的 Hibernate 实体关联的所有表。