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:
DROP TABLE <table> [IF EXISTS] [RESTRICT | CASCADE];
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:
2016-07-12 14:33:06,639 WARN [ExceptionHandlerLoggedImpl] GenerationTarget encountered exception accepting command : Unable to execute command [alter table SINGULARKONSTRAINT drop constraint FKj7t94rc7oab2i1kmur42hjc98]
org.hibernate.tool.schema.spi.CommandAcceptanceException: Unable to execute command [alter table SINGULARKONSTRAINT drop constraint FKj7t94rc7oab2i1kmur42hjc98]
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:63)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlString(SchemaDropperImpl.java:370)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlStrings(SchemaDropperImpl.java:355)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.applyConstraintDropping(SchemaDropperImpl.java:327)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.dropFromMetadata(SchemaDropperImpl.java:229)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.performDrop(SchemaDropperImpl.java:153)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:125)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:111)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:137)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:65)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:308)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:483)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:707)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:723)
Caused by: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: PUBLIC.SINGULARKONSTRAINT
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.execute(Unknown Source)
at org.apache.commons.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264)
at org.apache.commons.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264)
at org.apache.commons.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264)
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:51)
... 68 more
Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: PUBLIC.SINGULARKONSTRAINT
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.SchemaManager.getUserTable(Unknown Source)
at org.hsqldb.ParserDDL.compileAlterTable(Unknown Source)
at org.hsqldb.ParserDDL.compileAlter(Unknown Source)
at org.hsqldb.ParserCommand.compilePart(Unknown Source)
at org.hsqldb.ParserCommand.compileStatements(Unknown Source)
at org.hsqldb.Session.executeDirectStatement(Unknown Source)
at org.hsqldb.Session.execute(Unknown Source)
... 74 more
|