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

Emmanuel Bernard emmanuel at hibernate.org
Fri Aug 26 04:16:21 EDT 2016


Can you give HotRod's example of native enum - I imagine Protobuf ?

The issue I see is that ordinal could be an acceptable explicit decision
that would not be available to the user if you use default as native.

I'm tempted to go native all the time at the detriment of people that
need high customization.

Emmanuel

On Mon 2016-08-15 18:14, Sanne Grinovero wrote:
> 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
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev


More information about the hibernate-dev mailing list