简体   繁体   中英

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

I am trying to drop a foreign key constraint in a table but the SQL "DROP CONSTRAINT" Statement is not supported by ucanaccess. the error says:

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

Does anybody know a way around this?

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;");
            }
        }
}

The error message implies that setting hbm2ddl.auto to create would solve the problem:

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

However, you might want to think twice before doing this, as this means that all the tables associated with your Hibernate entities will be created and dropped each time you start the application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM