diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java index 651af16e84..3c47432487 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java @@ -682,7 +682,7 @@ public abstract class Dialect implements ConversionContext { * Render a SQL check condition for a column that represents an enumerated value. */ public String getCheckCondition(String columnName, long min, long max) { - return columnName + " between " + min + " and " + max; + return columnName + " between " + min + " and " + max; } /** diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/convert/internal/NamedEnumValueConverter.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/convert/internal/NamedEnumValueConverter.java index a1f4e2b61f..df2c639bbf 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/convert/internal/NamedEnumValueConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/convert/internal/NamedEnumValueConverter.java @@ -21,6 +21,7 @@ import org.hibernate.type.descriptor.java.EnumJavaType; import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.descriptor.jdbc.JdbcType; +import static java.util.Arrays.sort; import static org.hibernate.metamodel.model.convert.internal.EnumHelper.getEnumeratedValues; /** @@ -108,6 +109,8 @@ public class NamedEnumValueConverter> implements EnumValueConv @Override public String getSpecializedTypeDeclaration(JdbcType jdbcType, Dialect dialect) { - return dialect.getEnumTypeDeclaration( getEnumeratedValues( getDomainJavaType().getJavaTypeClass() ) ); + String[] values = getEnumeratedValues( getDomainJavaType().getJavaTypeClass() ); + sort( values ); //sort alphabetically, to guarantee alphabetical ordering in queries with 'order by' + return dialect.getEnumTypeDeclaration( values ); } }