@TypeDef doesn't work for enums

Description

@TypeDef is supposed to allow users to define standard types to be used for specific classes. However, due to a bug in implementation, it simply doesn't work for enums.

Enums are implicitly handled by the JPA spec. However, if a @TypeDef is defined for a particular enum, it will never be picked up due to bug in org.hibernate.cfg.annotations.SimpleValueBinder .

This class has a concept of a "explicitType", i.e., a type that was explicitly specified for a property. However, even if @EnumType is not used to annotate a property, method setType(XProperty,XClass) considers the property as annotated with it. Then, when fillSimpleValue() is called as part of second-pass compilation, the ternary in line 344 chooses org.hibernate.type.EnumType instead of the enum FQN, causing any @TypeDef to be ignored.

This behaviour should be fixed by considering a non-annotated enum property as implicitly typed, not explicitly. Then, the resolution order should be changed to explicitType -> returnedClassName -> implicitType. This would preserve default, expected behaviour for regular enums, while allowing @TypeDef to be used for enums as well.

Environment

hibernate-jpa-2.0-api:1.0.1-Final; hibernate-core:4.1.0.Final; hibernate-entitymanager:4.1.0.Final

Assignee

Strong Liu

Reporter

Michael Nascimento

Fix versions

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure