I also tried setting "hibernate.hbm2ddl.auto" property to "create" and got the same results.
Here is my code that builds that database:
Code:
public class HibernateTestUtil {
private static final String jdbc_url = "jdbc:hsqldb:mem:OPTools";
private static final String jdbc_username = "sa";
private static final String jdbc_password = "";
private static SessionFactory testSessionFactory;
private static void initializeSessionFactory() throws HibernateException {
Configuration config;
config = new Configuration().
// setProperty("hibernate.dialect", "net.sf.hibernate.dialect.HSQLDialect").
setProperty("hibernate.dialect", "net.sf.hibernate.dialect.HSQLSeqDialect").
setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver").
setProperty("hibernate.connection.url", jdbc_url).
setProperty("hibernate.connection.username", jdbc_username).
setProperty("hibernate.connection.password", jdbc_password).
setProperty("hibernate.connection.pool_size", "2").
setProperty("hibernate.connection.autocommit", "true").
setProperty("hibernate.cache.provider_class", "net.sf.hibernate.cache.HashtableCacheProvider").
setProperty("hibernate.hbm2ddl.auto", "create").
setProperty("hibernate.show_sql", "true").
addClass(Action.class).
addClass(Actionrequiredpermission.class).
addClass(Contract.class).
addClass(Market.class).
addClass(Systemuser.class).
addClass(Transactiontype.class).
addClass(Workorder.class).
addClass(Workorderaudit.class).
addClass(Workorderauthorization.class).
addClass(Workordercheck.class).
addClass(Workordercomment.class).
addClass(Workordercorrection.class).
addClass(Workorderfix.class).
addClass(Workorderfixinfo.class).
addClass(Workordergroup.class).
addClass(Workordergrouping.class).
addClass(Workorderinbox.class).
addClass(Workorderoperation.class).
addClass(Workorderoutbox.class).
addClass(Workorderremedyinfo.class).
addClass(Workorderrole.class).
addClass(Workordershadow.class).
addClass(Workordersymptom.class).
addClass(Workordertransaction.class).
addClass(Workordertransactioncomment.class).
addClass(Workordertransactionreference.class).
addClass(Workorderviewer.class);
testSessionFactory = config.buildSessionFactory();
}
public static synchronized SessionFactory getSessionFactory()
throws HibernateException {
if (testSessionFactory == null) {
initializeSessionFactory();
}
return testSessionFactory;
}
}
Here's my HSQLDBSeqDialect class that adds the support for sequences from Hibernate 3. It remains untested as I can't get the database to load properly.
Code:
package net.sf.hibernate.dialect;
import java.sql.SQLException;
import net.sf.hibernate.dialect.HSQLDialect;
import net.sf.hibernate.exception.ErrorCodeConverter;
import net.sf.hibernate.exception.JDBCExceptionHelper;
import net.sf.hibernate.exception.TemplatedViolatedConstraintNameExtracter;
import net.sf.hibernate.exception.ViolatedConstraintNameExtracter;
/**
* An SQL dialect compatible with HSQLDB sequences (HSQLDB version 1.7.2+)
* This is backported from Hibernate 3 in order to enable unit testing with Hibernate2
* against HsqlDB with mappings that use sequences.
*
* @author Matt Campbell
*/
public class HSQLSeqDialect extends HSQLDialect {
public String getSequenceNextValString(String sequenceName) {
return "select next value for " + sequenceName
+ " from SYSTEM_SEQUENCES";
}
// public String getSequenceNextValString(String sequenceName) {
// return "select next value for " + sequenceName + " from dual_" + sequenceName;
// }
public String getCreateSequenceString(String sequenceName) {
return "create sequence " + sequenceName;
}
// public String[] getCreateSequenceStrings(String sequenceName) {
// return new String[]{
// "create table dual_" + sequenceName + " (zero integer)",
// "insert into dual_" + sequenceName + " values (0)",
// "create sequence " + sequenceName + " start with 1"
// };
// }
public String getDropSequenceString(String sequenceName) {
return "drop sequence " + sequenceName;
}
// public String[] getDropSequenceStrings(String sequenceName) {
// return new String[]{
// "drop table dual_" + sequenceName + " if exists",
// "drop sequence " + sequenceName
// };
// }
public boolean supportsSequences() {
return true;
}
public String getQuerySequencesString() {
return "select sequence_name from system_sequences";
}
private static class ExceptionConverter extends ErrorCodeConverter {
private int[] sqlGrammarCodes = new int[]{-22, -28};
private int[] integrityViolationCodes = new int[]{-8, -9, -177, -104};
public ExceptionConverter(ViolatedConstraintNameExtracter extracter) {
super( extracter );
}
protected int[] getSQLGrammarErrorCodes() {
return sqlGrammarCodes;
}
protected int[] getIntegrityViolationErrorCodes() {
return integrityViolationCodes;
}
}
public ViolatedConstraintNameExtracter getViolatedConstraintNameExtracter() {
return EXTRACTER;
}
private static ViolatedConstraintNameExtracter EXTRACTER = new TemplatedViolatedConstraintNameExtracter() {
/**
* Extract the name of the violated constraint from the given SQLException.
*
* @param sqle The exception that was the result of the constraint violation.
* @return The extracted constraint name.
*/
public String extractConstraintName(SQLException sqle) {
String constraintName = null;
int errorCode = JDBCExceptionHelper.extractErrorCode(sqle);
if ( errorCode == -8 ) {
constraintName = extractUsingTemplate( "Integrity constraint violation ", " table:", sqle.getMessage() );
}
else if ( errorCode == -9 ) {
constraintName = extractUsingTemplate( "Violation of unique index: ", " in statement [", sqle.getMessage() );
}
else if ( errorCode == -104 ) {
constraintName = extractUsingTemplate( "Unique constraint violation: ", " in statement [", sqle.getMessage() );
}
else if ( errorCode == -177 ) {
constraintName = extractUsingTemplate( "Integrity constraint violation - no parent ", " table:", sqle.getMessage() );
}
return constraintName;
}
};
}