[hibernate-dev] Mapping JPA's @MapKeyEnumerated and @Enumerated on native-enum supporting datastores

Sanne Grinovero sanne at hibernate.org
Mon Aug 15 13:14:45 EDT 2016


In the context of Hibernate OGM, it turns out that some datastores
have a rather nice "native" support for enums.

We aim to map each property of the user's domain model to its most
appropriate "physical type", unless the choice is overriden by the an
explicit user request.

In the case of an Enum, JPA annotations such as @Enumerated have an
attribute EnumType to choose the physical representation:

public enum EnumType {
    /** Persist enumerated type property or field as an integer. */
    ORDINAL,

    /** Persist enumerated type property or field as a string. */
    STRING
}

However, there's no support for a "NATIVE". Also, the annotation
specifies that "ORDINAL" is the default value so I can't just assume
that the user didn't specify anything and we're good to use our own
NATIVE implementation.

Assuming that we can't change the JPA spec, any suggestion on when I
could have the Hot Rod dialect for OGM to actually produce a "nice"
mapping into native enums?

I'm tempted to just use natives all the time; In the case in which the
user opted for "STRING" I could drop a warning - or decide to honour
that - but in case of ORDINAL I just can't tell if it's a default
choice or not so I think a warning would be too much.

Another alternative would be that I "go native" when the @Enumerated
annotation isn't specified at all: looks like this mapping is valid
according to ORM as it seems to treat it as if there was an implicit
@Enumerated annotation; I'm not happy about having to rely on people
to not use an explicit annotation though.

Thanks,
Sanne


More information about the hibernate-dev mailing list