mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#863 - @Enumerated(EnumType.STRING) DayOfWeek day; ... incorrectly maps to SQL Integer type
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user