HHH-15845 sort enum values on MySQL

This commit is contained in:
Gavin 2022-12-12 19:02:34 +01:00 committed by Gavin King
parent a5525a943f
commit 919278aac2
2 changed files with 5 additions and 2 deletions

View File

@ -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 );
} }
} }