#1329 - Ebean 11.12.1 broken when using ScalarTypeConverter with enum

This commit is contained in:
Rob Bygrave
2018-03-05 19:19:27 +13:00
parent 130356cb3b
commit 740532da4b
5 changed files with 81 additions and 11 deletions
@@ -588,21 +588,27 @@ public final class DefaultTypeManager implements TypeManager {
@Override
public ScalarType<?> createEnumScalarType(Class<? extends Enum<?>> enumType, EnumType type) {
ScalarTypeEnum<?> scalarType = (ScalarTypeEnum<?>) getScalarType(enumType);
if (scalarType != null && !scalarType.isOverrideBy(type)) {
if (type != null && !scalarType.isCompatible(type)) {
throw new IllegalStateException("Error mapping Enum type:" + enumType + " It is mapped using 2 different modes when only one is supported (ORDINAL, STRING or an Ebean mapping)");
}
ScalarType<?> scalarType = getScalarType(enumType);
if (scalarType instanceof ScalarTypeWrapper) {
// no override or further mapping required
return scalarType;
}
scalarType = createEnumScalarTypePerExtentions(enumType);
if (scalarType == null) {
// use JPA normal Enum type (without mapping)
scalarType = createEnumScalarTypePerSpec(enumType, type);
ScalarTypeEnum<?> scalarEnum = (ScalarTypeEnum<?>)scalarType;
if (scalarEnum != null && !scalarEnum.isOverrideBy(type)) {
if (type != null && !scalarEnum.isCompatible(type)) {
throw new IllegalStateException("Error mapping Enum type:" + enumType + " It is mapped using 2 different modes when only one is supported (ORDINAL, STRING or an Ebean mapping)");
}
return scalarEnum;
}
addEnumType(scalarType, enumType);
return scalarType;
scalarEnum = createEnumScalarTypePerExtentions(enumType);
if (scalarEnum == null) {
// use JPA normal Enum type (without mapping)
scalarEnum = createEnumScalarTypePerSpec(enumType, type);
}
addEnumType(scalarEnum, enumType);
return scalarEnum;
}
private ScalarTypeEnum<?> createEnumScalarTypePerSpec(Class<?> enumType, EnumType type) {