#863 - @Enumerated(EnumType.STRING) DayOfWeek day; ... incorrectly maps to SQL Integer type

This commit is contained in:
Rob Bygrave
2016-11-07 17:15:47 +13:00
parent 51364763fb
commit 63f852475d
@@ -117,6 +117,10 @@ public class DeployUtil {
throw new IllegalArgumentException("Class [" + enumType + "] is Not a Enum?");
}
ScalarType<?> scalarType = typeManager.getScalarType(enumType);
if (enumOverrideDefaultMapping(enumerated, scalarType)) {
logger.debug("override default enum mapping for type {}", enumType);
scalarType = null;
}
if (scalarType == null) {
// look for @DbEnumValue or @EnumValue annotations etc
Class<? extends Enum<?>> enumClass = (Class<? extends Enum<?>>)enumType;
@@ -133,6 +137,17 @@ public class DeployUtil {
prop.setDbType(scalarType.getJdbcType());
}
/**
* Return true if there is an existing default mapping for the enum that needs
* to be overridden (for example, DayOfWeek defaults to Integer mapping 1 to 7
* and some might want this mapped to 'MONDAY' etc).
*/
private boolean enumOverrideDefaultMapping(Enumerated enumerated, ScalarType<?> scalarType) {
return enumerated != null && scalarType != null
&& enumerated.value() == EnumType.STRING
&& scalarType.getJdbcType() != Types.VARCHAR;
}
private ScalarType<?> createEnumScalarTypePerSpec(Class<?> enumType, EnumType type) {
if (type == null) {