diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java index 4c92b27d55..369476b148 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java @@ -19,7 +19,8 @@ import org.hibernate.dialect.identity.IdentityColumnSupport; import org.hibernate.dialect.pagination.LimitHandler; import org.hibernate.dialect.pagination.LimitOffsetLimitHandler; import org.hibernate.dialect.pagination.OffsetFetchLimitHandler; -import org.hibernate.dialect.sequence.H2SequenceSupport; +import org.hibernate.dialect.sequence.H2V1SequenceSupport; +import org.hibernate.dialect.sequence.H2V2SequenceSupport; import org.hibernate.dialect.sequence.SequenceSupport; import org.hibernate.dialect.temptable.TemporaryTable; import org.hibernate.dialect.temptable.TemporaryTableKind; @@ -76,6 +77,7 @@ public class H2Dialect extends Dialect { private final LimitHandler limitHandler; + private final boolean ansiSequence; private final boolean cascadeConstraints; private final boolean useLocalTime; @@ -105,6 +107,11 @@ public class H2Dialect extends Dialect { } supportsTuplesInSubqueries = version.isSameOrAfter( 1, 4, 198 ); + + // Prior to 1.4.200 there was no support for 'current value for sequence_name' + // After 2.0.202 there is no support for 'sequence_name.nextval' and 'sequence_name.currval' + ansiSequence = version.isSameOrAfter( 1, 4, 200 ); + // Prior to 1.4.200 the 'cascade' in 'drop table' was implicit cascadeConstraints = version.isSameOrAfter( 1, 4, 200 ); // 1.4.200 introduced changes in current_time and current_timestamp @@ -379,7 +386,7 @@ public class H2Dialect extends Dialect { @Override public SequenceSupport getSequenceSupport() { - return H2SequenceSupport.INSTANCE; + return ansiSequence ? H2V2SequenceSupport.INSTANCE: H2V1SequenceSupport.INSTANCE; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/sequence/H2SequenceSupport.java b/hibernate-core/src/main/java/org/hibernate/dialect/sequence/H2V1SequenceSupport.java similarity index 85% rename from hibernate-core/src/main/java/org/hibernate/dialect/sequence/H2SequenceSupport.java rename to hibernate-core/src/main/java/org/hibernate/dialect/sequence/H2V1SequenceSupport.java index 3e4768555f..af18270203 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/sequence/H2SequenceSupport.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/sequence/H2V1SequenceSupport.java @@ -13,9 +13,9 @@ import org.hibernate.MappingException; * * @author Gavin King */ -public final class H2SequenceSupport implements SequenceSupport { +public final class H2V1SequenceSupport implements SequenceSupport { - public static final SequenceSupport INSTANCE = new H2SequenceSupport(); + public static final SequenceSupport INSTANCE = new H2V1SequenceSupport(); @Override public String getDropSequenceString(String sequenceName) { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/sequence/H2V2SequenceSupport.java b/hibernate-core/src/main/java/org/hibernate/dialect/sequence/H2V2SequenceSupport.java new file mode 100644 index 0000000000..e649d38d69 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/dialect/sequence/H2V2SequenceSupport.java @@ -0,0 +1,22 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.dialect.sequence; + +/** + * Sequence support for {@link org.hibernate.dialect.H2Dialect}. + * + * @author Gavin King + */ +public final class H2V2SequenceSupport extends ANSISequenceSupport { + + public static final SequenceSupport INSTANCE = new H2V2SequenceSupport(); + + @Override + public String getDropSequenceString(String sequenceName) { + return "drop sequence if exists " + sequenceName; + } +}