[hibernate-issues] [Hibernate-JIRA] Created: (HHH-7108) @TypeDef doesn't work for enums

Michael Nascimento Santos (JIRA) noreply at atlassian.com
Thu Feb 23 07:16:48 EST 2012


@TypeDef doesn't work for enums
-------------------------------

                 Key: HHH-7108
                 URL: https://hibernate.onjira.com/browse/HHH-7108
             Project: Hibernate ORM
          Issue Type: Bug
          Components: core
    Affects Versions: 4.1.0
         Environment: hibernate-jpa-2.0-api:1.0.1-Final; hibernate-core:4.1.0.Final; hibernate-entitymanager:4.1.0.Final 
            Reporter: Michael Nascimento Santos
            Priority: Critical


@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.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list