HHH-15845 sort enum values on MySQL
This commit is contained in:
parent
a5525a943f
commit
919278aac2
|
@ -682,7 +682,7 @@ public abstract class Dialect implements ConversionContext {
|
||||||
* Render a SQL check condition for a column that represents an enumerated value.
|
* Render a SQL check condition for a column that represents an enumerated value.
|
||||||
*/
|
*/
|
||||||
public String getCheckCondition(String columnName, long min, long max) {
|
public String getCheckCondition(String columnName, long min, long max) {
|
||||||
return columnName + " between " + min + " and " + max;
|
return columnName + " between " + min + " and " + max;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,6 +21,7 @@ import org.hibernate.type.descriptor.java.EnumJavaType;
|
||||||
import org.hibernate.type.descriptor.java.JavaType;
|
import org.hibernate.type.descriptor.java.JavaType;
|
||||||
import org.hibernate.type.descriptor.jdbc.JdbcType;
|
import org.hibernate.type.descriptor.jdbc.JdbcType;
|
||||||
|
|
||||||
|
import static java.util.Arrays.sort;
|
||||||
import static org.hibernate.metamodel.model.convert.internal.EnumHelper.getEnumeratedValues;
|
import static org.hibernate.metamodel.model.convert.internal.EnumHelper.getEnumeratedValues;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -108,6 +109,8 @@ public class NamedEnumValueConverter<E extends Enum<E>> implements EnumValueConv
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSpecializedTypeDeclaration(JdbcType jdbcType, Dialect dialect) {
|
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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue