From 9b57337a8599e7c359c3c7e2f8e702a272027f71 Mon Sep 17 00:00:00 2001 From: Brett Meyer Date: Tue, 4 Mar 2014 09:55:40 -0500 Subject: [PATCH] HHH-9017 correct HSQL pooled sequences --- .../java/org/hibernate/dialect/HSQLDialect.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java index f88f85b260..a6d8b5a50b 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java @@ -29,6 +29,7 @@ import java.sql.Types; import org.hibernate.JDBCException; import org.hibernate.LockMode; +import org.hibernate.MappingException; import org.hibernate.StaleObjectStateException; import org.hibernate.cfg.Environment; import org.hibernate.dialect.function.AvgWithArgumentCastFunction; @@ -312,10 +313,26 @@ public class HSQLDialect extends Dialect { return true; } + /** + * HSQL will start with 0, by default. In order for Hibernate to know that this not transient, + * manually start with 1. + */ @Override protected String getCreateSequenceString(String sequenceName) { return "create sequence " + sequenceName + " start with 1"; } + + /** + * Because of the overridden {@link #getCreateSequenceString(String)}, we must also override + * {@link #getCreateSequenceString(String, int, int)} to prevent 2 instances of "start with". + */ + @Override + protected String getCreateSequenceString(String sequenceName, int initialValue, int incrementSize) throws MappingException { + if ( supportsPooledSequences() ) { + return "create sequence " + sequenceName + " start with " + initialValue + " increment by " + incrementSize; + } + throw new MappingException( getClass().getName() + " does not support pooled sequences" ); + } @Override protected String getDropSequenceString(String sequenceName) {