org.hibernate.dialect.Dialect does not support 'CASCADE' following '<TABLENAME> IF EXISTS'

Description

After upgrading to Hibernate 5.2 I started seeing exceptions thrown during test initialization of an in-memory database with HSQLDB. With version 4.1 these were reduced to single line errors messages, but in 5.2 the entire stack trace is printed (at the bottom of this description) obscuring test details.

The root cause is that HSQLDB throws an exception if DROP CONSTRAINT is used on a non-existent table even if the 'IF EXISTS' clause is added. HSQL recommends dropping the constraints with the table (per https://sourceforge.net/p/hsqldb/feature-requests/299/).

The HSQLDB syntax for DROP TABLE is:

Note that 'CASCADE' follows the 'IF EXISTS' clause. However, org.hibernate.dialect.Dialect#getDropTableString() and org.hibernate.tool.schema.internal.StandardTableExporter#getSqlDropStrings() only permit the cascade statement returned by Dialect#getCascadeConstraintsString() to be placed between the table name and 'IF EXISTS' clause, not after the IF EXISTS clause.

Thus, HSQL DELETE TABLE <tablename> IF EXISTS CASCADE cannot be supported without creating a custom Dialect that returns a custom Exporter<Table> to override the generation of the DROP TABLE string.

Note that I also believe the default HSQLDialect should return false for dropConstraints() and use the DROP TABLE ... CASCADE option instead.

Here is the stack trace snippet while constructing tables during test initialization:

Environment

None

Activity

Show:
Gail Badner
July 14, 2016, 7:18 PM

Please create a pull request with a test case that reproduces your issue and your fix to HSQLDialect.

Will Darby
July 15, 2016, 3:43 PM

Ok - I haven't done that before. Can you point me to a reference on setting up an environment to create a test suitable for Hibernate?

Assignee

Unassigned

Reporter

Will Darby

Fix versions

None

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Minor
Configure